Issue |
154033
|
Summary |
static_cast involving pointers to members is too strict during constant evaluation
|
Labels |
new issue
|
Assignees |
|
Reporter |
Halalaluyafail3
|
The following program demonstrates this issue:
```cpp
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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs