[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 20 12:15:19 PST 2024


================
@@ -3566,6 +3613,21 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
   }
 
   Result = VD->getEvaluatedValue();
+
+  // C++23 [expr.const]p8
+  // ... For such an object that is not usable in constant expressions, the
+  // dynamic type of the object is constexpr-unknown. For such a reference that
+  // is not usable in constant expressions, the reference is treated as binding
+  // to an unspecified object of the referenced type whose lifetime and that of
+  // all subobjects includes the entire constant evaluation and whose dynamic
+  // type is constexpr-unknown.
+  if (AllowConstexprUnknown) {
+    if (!Result) {
+      Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
+    } else {
+      Result->setConstexprUnknown();
+    }
----------------
cor3ntin wrote:

```suggestion
    if (!Result)
      Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
    else
      Result->setConstexprUnknown();
```

(Or use a ternary)

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


More information about the cfe-commits mailing list