[clang] [clang] Diagnose VLA types from an enclosing function in local classes and blocks (PR #229697)
Ivan Ugryumov via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 01:59:22 PST 2026
================
@@ -4860,29 +4956,14 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(QualType ExprType,
ExprKind))
return true;
- if (ExprType->isVariablyModifiedType() && FunctionScopes.size() > 1) {
- if (auto *TT = ExprType->getAs<TypedefType>()) {
- for (auto I = FunctionScopes.rbegin(),
- E = std::prev(FunctionScopes.rend());
- I != E; ++I) {
- auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
- if (CSI == nullptr)
- break;
- DeclContext *DC = nullptr;
- if (auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
- DC = LSI->CallOperator;
- else if (auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
- DC = CRSI->TheCapturedDecl;
- else if (auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
- DC = BSI->TheDecl;
- if (DC) {
- if (DC->containsDecl(TT->getDecl()))
- break;
- captureVariablyModifiedType(Context, ExprType, CSI);
- }
- }
- }
- }
+ // The operand of sizeof is parsed in an unevaluated context, but a variably
+ // modified operand is evaluated if the sizeof itself is.
+ std::optional<EnterExpressionEvaluationContext> Evaluated;
+ if ((ExprKind == UETT_SizeOf || ExprKind == UETT_CountOf) &&
+ isUnevaluatedContext())
+ Evaluated.emplace(*this, parentEvaluationContext().Context);
+ if (!CheckVariablyModifiedTypeUse(ExprType, OpLoc))
----------------
Servall4 wrote:
Moved it after `TransformToPotentiallyEvaluated()`. That only runs when the bound is written inside the sizeof, so for sizeof(X) with a typedef we're still in the unevaluated context and still need the EnterExpressionEvaluationContext before the check.
https://github.com/llvm/llvm-project/pull/229697
More information about the cfe-commits
mailing list