-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Closed
Copy link
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constevalC++20 constevalC++20 consteval
Description
The following program demonstrates this issue:
consteval int foo(){
struct A{char x;};
struct B{char y;};
struct C:A,B{};
char C::*p=&A::x;
char B::*q=static_cast<char B::*>(p);
C c{};
return((B&)c).*q;
}
int main(){
return foo();
}
Clang rejects this code complaining about the static_cast, while GCC accepts it. Also, MSVC will crash with this code. This code should be fine because https://eel.is/c++draft/expr.static.cast#11.sentence-5 says "If class B contains the original member, or is a base class of the class containing the original member, the resulting pointer to member points to the original member." B
here does not contain the member A::x
, but it is a base class of C
which contains the member.
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constevalC++20 constevalC++20 consteval