[clang] [clang] Diagnose VLA types from an enclosing function in local classes and blocks (PR #229697)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 10 16:47:35 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))
----------------
efriedma-quic wrote:

We probably want to do this check after the call to TransformToPotentiallyEvaluated(); it could affect what is captured.

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


More information about the cfe-commits mailing list