[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 15 09:37:42 PST 2024
================
@@ -2487,14 +2487,19 @@ bool VarDecl::mightBeUsableInConstantExpressions(const ASTContext &C) const {
if (!getType().isConstant(C) || getType().isVolatileQualified())
return false;
- // In C++, const, non-volatile variables of integral or enumeration types
- // can be used in constant expressions.
- if (getType()->isIntegralOrEnumerationType())
+ // In C++, but not in C, const, non-volatile variables of integral or
+ // enumeration types can be used in constant expressions.
+ if (getType()->isIntegralOrEnumerationType() && !Lang.C23)
----------------
AaronBallman wrote:
We might want to relax this in the future because we *do* allow const, non-volatile integer variables in constant expressions in C: https://godbolt.org/z/jc1h49Wox
But I think the code is fine for now because I think the function is not accurate in other ways:
```
// Function parameters are never usable in constant expressions.
if (isa<ParmVarDecl>(this))
return false;
```
which is not quite the case: https://godbolt.org/z/Kdq9xY617 and yet is the case: https://godbolt.org/z/1zEGsbYfn
https://github.com/llvm/llvm-project/pull/73099
More information about the cfe-commits
mailing list