[clang] Fix crash with modules and constexpr destructor (PR #69076)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 7 23:25:27 PST 2024


================
@@ -15754,10 +15754,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
     LValue LVal;
     LVal.set(VD);
 
-    if (!EvaluateInPlace(Value, Info, LVal, this,
-                         /*AllowNonLiteralTypes=*/true) ||
-        EStatus.HasSideEffects)
-      return false;
+    {
+      // C++23 [intro.execution]/p5
+      // A full-expression is ... an init-declarator ([dcl.decl]) or a
+      // mem-initializer.
+      // So we need to make sure temporary objects are destroyed after having
+      // evaluated the expression (per C++23 [class.temporary]/p4).
----------------
ChuanqiXu9 wrote:

```suggestion
      // evaluated the expression (per C++23 [class.temporary]/p4).
      //
      // FIXME: Otherwise this may break test/Modules/pr68702.cpp. because the serialization code 
      // calls ParmVarDecl::getDefaultArg() which strips the outermost FullExpr, such as ExprWithCleanups. 
```

I mean the reason why this is related to modules. I feel the analysis is valuable.

https://github.com/llvm/llvm-project/pull/69076


More information about the cfe-commits mailing list