[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 10 19:06:37 PDT 2025
================
@@ -5218,16 +5218,28 @@ static bool EvaluateVarDecl(EvalInfo &Info, const VarDecl *VD) {
return true;
}
+static bool EvaluateDecompositionDeclInit(EvalInfo &Info,
+ const DecompositionDecl *DD);
+
static bool EvaluateDecl(EvalInfo &Info, const Decl *D) {
bool OK = true;
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
OK &= EvaluateVarDecl(Info, VD);
- if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(D))
- for (auto *BD : DD->flat_bindings())
- if (auto *VD = BD->getHoldingVar())
- OK &= EvaluateDecl(Info, VD);
+ if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(D);
+ DD && !DD->isDecisionVariable())
+ OK &= EvaluateDecompositionDeclInit(Info, DD);
+
+ return OK;
+}
+
+static bool EvaluateDecompositionDeclInit(EvalInfo &Info,
+ const DecompositionDecl *DD) {
+ bool OK = true;
+ for (auto *BD : DD->flat_bindings())
+ if (auto *VD = BD->getHoldingVar())
+ OK &= EvaluateDecl(Info, VD);
----------------
zyn0217 wrote:
And we crash during `isPotentialConstantExpr()`, wherein we set `CheckingPotentialConstantExpression = true` that results in `EvaluateVarDecl()` returning true because `EvaluateInPlace()` it called bailed out of evaluation in this case. So in short, we can't short-circuit the initialization of the binding decls because they're necessary in `CheckingPotentialConstantExpression`.
https://github.com/llvm/llvm-project/pull/130228
More information about the cfe-commits
mailing list