consteval constructor cannot store this inside object (original) (raw)
Unlike GCC & MSVC, Clang refuses to compile this https://godbolt.org/z/WYr58Ge9s --
struct B { const void* immortal_; consteval B() : immortal_{this} {} }; constexpr static B b;
The error suggests that the frontend wrongly thinks that this is a pointer to a temporary:
<source>:6:20: error: call to consteval function 'B::B' is not a constant expression
6 | constexpr static B b;
| ^
<source>:6:20: note: pointer to temporary is not a constant expression
<source>:6:20: note: temporary created here