[clang] [clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (PR #112211)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 07:50:17 PDT 2024
================
@@ -348,6 +348,12 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
if (D->isConstexpr())
return true;
+ if (const auto *VD = dyn_cast_if_present<VarDecl>(S.EvaluatingDecl);
----------------
yronglin wrote:
It's to follow the logic in https://github.com/llvm/llvm-project/blob/839344f025fb7eff529735873f327330618b2ebb/clang/lib/AST/ExprConstant.cpp#L4341-L4344 .
If `EvaluatingDecl` is constexpr, but D is not a constexpr, it's not allow in C23. For example, the code in PR's description, `V37` is a constexpr, but it's references non-constexpr variable `V33` and `V35`.
https://github.com/llvm/llvm-project/pull/112211
More information about the cfe-commits
mailing list