Skip to content

Improve error message for constexpr constructors of virtual base classes #64843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Eisenwave opened this issue Aug 20, 2023 · 3 comments
Closed
Labels
awaiting-review Has pending Phabricator review clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party

Comments

@Eisenwave
Copy link

Code to Reproduce (https://godbolt.org/z/6EhPfTTfE)

struct Base {
  constexpr Base() = default;
};
struct Derived : virtual Base {
  constexpr Derived() = default;
};

Clang diagnostic:

<source>:5:3: error: defaulted definition of default constructor is not constexpr
    5 |   constexpr Derived() = default;
      |   ^

GCC diagnostic:

<source>:5:13: error: explicitly defaulted function 'constexpr Derived::Derived()' cannot be declared 'constexpr' because the implicit declaration is not 'constexpr':
    5 |   constexpr Derived() = default;
      |             ^~~~~~~

MSVC diagnostic:

<source>(5): error C2468: constructor cannot be 'constexpr' in a class or struct with virtual base classes
<source>(6): note: see reference to function 'Derived::Derived(void)'

Suggested Resolution

Out of the three, the MSVC diagnostic seems best. It would be nice if clang could output something similar.

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Aug 20, 2023
@shafik shafik added the confirmed Verified by a second party label Aug 21, 2023
@shafik
Copy link
Collaborator

shafik commented Aug 21, 2023

Confirmed

@NoumanAmir657
Copy link
Contributor

I would like to work on this issue.
Since, I am new to this can someone give me a brief overview of what to do.
I am assuming I have to find the diagnostics file where this error is generated and change the error string to MSVC one.

@NoumanAmir657
Copy link
Contributor

@xgupta xgupta added the awaiting-review Has pending Phabricator review label Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Has pending Phabricator review clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

5 participants