Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,13 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
}
DeclGroupPtrTy DG;
SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
if (Tok.is(tok::kw_using)) {
if (!getLangOpts().CPlusPlus &&
Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
ProhibitAttributes(attrs);
Decl *D = ParseStaticAssertDeclaration(DeclEnd);
DG = Actions.ConvertDeclToDeclGroup(D);
FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
} else if (Tok.is(tok::kw_using)) {
DG = ParseAliasDeclarationInInitStatement(DeclaratorContext::ForInit,
attrs);
FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Sema/for.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ void b10(void) { for (typedef struct { int i; } (*s)(struct { int j; });;); } /*
void b11 (void) { for (static _Thread_local struct { int i; } s;s.i;); } /* c11-warning {{declaration of non-local variable in 'for' loop is a C23 extension}}
c23-warning {{declaration of non-local variable in 'for' loop is incompatible with C standards before C23}} */
#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}} */
}
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/for-static-assert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

// C permits a 'static_assert' in the first part of a 'for' loop
// whereas C++ does not.
void f() {
for(static_assert(true);;) {} // expected-error {{expected expression}}
}
Loading