[clang] [clang] Fixed inconsistent diagnostics when initializing a constexpr variable with a compound literal (PR #232825)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 23:11:38 PDT 2026


tbaederr wrote:

Unrelated to compound literals; In C23 we shouldn't allow reading from a non-constexpr variable if we're in a constant context.

For your example:
```c++
const int a = 1;
constexpr int b = a;
```
we disallow this here: https://github.com/llvm/llvm-project/blob/ef69409b93d30c3a92bba1431e8bffe5cd3a8c4e/clang/lib/AST/ExprConstant.cpp#L4842-L4844

That's because `ConstexprVar` is set, because we're getting here through `EvalauteAsInitializer`. But it seems like that condition isn't correct and we need to check `Info.getLangOpts().C23 && Info.InConstantContext` instead.

That's just a guess though, I haven't verified that this doesn't break any existing tests.



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


More information about the cfe-commits mailing list