-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluation
Description
First, the following code is rejected by clang but accepted by other compilers like GCC, MSVC, and ICC:
struct base { };
struct derived : virtual base {
constexpr int tst(){return 1;}
};
https://godbolt.org/z/rj63nKP4v
Clang reports the following message:
<source>:3:23: error: constexpr member function not allowed in struct with virtual base class
3 | constexpr int tst(){return 1;}
| ^
<source>:2:22: note: virtual base class declared here
2 | struct derived : virtual base {
| ^~~~~~~~~~~~
1 error generated.
The diagnostic seems not such necessary because member function tst
doesn't involve any override and can be specified during compile stage.
It's more interesting that the overloaded copy assignment operator is also accepted by other compilers, which definitely contains the instantiation of the virtual base class:
struct base { };
struct derived : virtual base {
//reject
//constexpr derived(const derived &)=default;
//reject
//constexpr derived(derived &&)=default;
//accept
constexpr derived& operator=(derived const&) =default;
};
https://godbolt.org/z/rYPEYTex8
Copy ctors and move ctors are always rejected though.
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluation