[C] static_assert in a for loop is not an extension (#151955)
The original wording can be squinted at to pretend this was always allowed. GCC squints at it that way, so we're doing the same and no longer issuing an extension diagnostic for use of static_assert in the condition-1 of a for loop in C. Fixes #149633 (cherry picked from commit cb50d78a0063244434d883d89ddda7f74abbffc9)
This commit is contained in:
parent
1d46440e9f
commit
d502822e68
@ -2287,6 +2287,10 @@ 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.
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user