Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
// we can diagnose if we don't see any variable declarations. This
// covers a case like declaring a typedef, function, or structure
// type rather than a variable.
NonVarSeen = DI;
//
// Note, _Static_assert is acceptable because it does not declare an
// identifier at all, so "for object having" does not apply.
if (!isa<StaticAssertDecl>(DI))
NonVarSeen = DI;
}
}
// Diagnose if we saw a non-variable declaration but no variable
Expand Down
3 changes: 1 addition & 2 deletions clang/test/Sema/for.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } s;s.i;); } /* c11-
#endif

void b12(void) {
for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 'for' loop is a C23 extension}}
c23-warning {{non-variable declaration in 'for' loop is incompatible with C standards before C23}} */
for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* identifiers */
}