Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -1826,7 +1826,10 @@ VarDecl *VD = dyn_cast(DI); if (VD && VD->isLocalVarDecl() && !VD->hasLocalStorage()) VD = nullptr; - if (!VD) { + // It is possible to declare non-variable declarations as part of the + // declaration part of a 'for' statement, such as defining a structure + // or enum type: for (enum { zero, ten } i = zero; i < ten; ++i); + if (!VD && !isa(DI)) { Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for); DI->setInvalidDecl(); } Index: clang/test/Sema/for.c =================================================================== --- clang/test/Sema/for.c +++ clang/test/Sema/for.c @@ -5,3 +5,5 @@ void b2 (void) { for (void f (void);;); } // expected-error {{declaration of non-local variable}} void b3 (void) { for (static int f;;); } // expected-error {{declaration of non-local variable}} void b4 (void) { for (typedef int f;;); } // expected-error {{declaration of non-local variable}} +void b5 (void) { for (struct { int i; } s;;); } +void b6 (void) { for (enum { zero, ten = 10 } i;;); }