[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 16 23:43:21 PST 2023


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+    // The This pointer is writable in constructors, even if
+    // isConst() returns true.
+    if (Ptr.block() == S.Current->getThis().block())
+      return true;
+  }
----------------
shafik wrote:
> shafik wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > The same is true for destructors as well: https://godbolt.org/z/a49aEErz8
> > > Oh, good catch, thanks.
> > Interesting case: https://godbolt.org/z/5r5fdh9jr
> > 
> > Implementation divergence, have to figure out who is correct here.
> I believe clang is correct: https://eel.is/c++draft/expr.const#4.8
The output is the same with the new constant interpreter; that case is probably handled before it's constant evaluated.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136751/new/

https://reviews.llvm.org/D136751



More information about the cfe-commits mailing list