AaronBallman wrote: > In this code: > > ```c++ > namespace ExplicitThisInTemporary { > struct B { B *p = this; }; > constexpr bool g(B b) { return &b == b.p; } > static_assert(g({}), ""); > } > ``` > > The AST for the `static_assert` expr is: > > ``` > CallExpr 0x52100009ed98 '_Bool' > |-ImplicitCastExpr 0x52100009ed78 '_Bool (*)(B)' <FunctionToPointerDecay> > | `-DeclRefExpr 0x5210000754a0 '_Bool (B)' lvalue Function 0x521000075188 'g' > '_Bool (B)' > `-InitListExpr 0x52100009edc8 'B':'struct ExplicitThisInTemporary::B' > `-CXXDefaultInitExpr 0x52100009ee20 'B *' has rewritten init > `-CXXThisExpr 0x521000075008 'struct ExplicitThisInTemporary::B *' this > ``` > > the `CXXThisExpr` here doesn't point to the current instance pointer of the > frame (that doesn't even exist), but to the object created by the > `InitListExpr` surrounding it (`0x52100009edc8`).
I believe that is correct. The `InitListExpr` is responsible for creating and initializing the `B` object (https://eel.is/c++draft/dcl.init#aggr-5) and `this` would refer to that object (https://eel.is/c++draft/expr.prim.this#4). CC @zygoloid @hubert-reinterpretcast @cor3ntin @shafik for some additional opinions. https://github.com/llvm/llvm-project/pull/106552 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits