================
@@ -5933,11 +5929,23 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   // expression is an ExprWithCleanups. Then make sure the normal lifetime
   // extension code recurses into the default initializer and does lifetime
   // extension when warranted.
+  //
+  // The initializer is rebuilt for *every* use, so that each
+  // CXXDefaultInitExpr owns its own copy of it. The initializer is written
+  // once but evaluated once per use, and `this` within it denotes whichever
+  // object that use initializes; sharing the nodes between uses would make
+  // the two indistinguishable to anything that keys state on `Expr *`.
+  //
+  // Only the rewrites above are semantic; the rest is a copy of an initializer
+  // that has already been checked where it was written. Re-checking it must
+  // therefore not diagnose a second time, and if re-checking fails to
+  // reproduce it we keep the one from the declaration instead of failing here.
   bool ContainsAnyTemporaries =
       isa_and_present<ExprWithCleanups>(Field->getInClassInitializer());
+  bool SemanticRebuild =
+      V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries);
   if (Field->getInClassInitializer() &&
-      !Field->getInClassInitializer()->containsErrors() &&
-      (V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries))) {
+      !Field->getInClassInitializer()->containsErrors() && SemanticRebuild) {
----------------
jvoung wrote:

Just copying the comment from discord -- is the `&& SemanticRebuild` here 
intentional?

Below at line 5961 there is `if (!SemanticRebuild)` which seems like it would 
end up as dead code?

https://github.com/llvm/llvm-project/pull/221299
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to