Issue |
81733
|
Summary |
Clang behaves somewhat weirdly with pointer to member field cast inside a class not completed and inheritance
|
Labels |
clang
|
Assignees |
|
Reporter |
Rush10233
|
The following code compiles normally in clang:
```c++
struct A { int i; };
struct B:A { int j; };
struct C:B { int k; static_assert((int(B::*))&C::k, ""); };
```
But it's rejected by gcc which complains that `&C::k` should not be constant before the class `C` is completed:
```c++
<source>:3:35: error: non-constant condition for static assertion
3 | struct C:B { int k; static_assert((int(B::*))&C::k, ""); };
| ^~~~~~~~~~~~~~~~
<source>:3:35: error: '&C::k' is not a constant _expression_ when the class 'C' is still incomplete
Compiler returned: 1
```
Note that the `static_assert` _expression_ requires its first parameter to be compile-time constant. It seems at least one of the compilers does the wrong thing. Since the standard of class member variable pointer assignment looks a little complex, we currently cannot judge for certain which behavior is reasonable. We hope that can be further identified.
[https://godbolt.org/z/MWeYx7sYq](https://godbolt.org/z/MWeYx7sYq)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs