This is an archive of the discontinued LLVM Phabricator instance.

Allow C11 static assert declaration as clause-1 in for loops.
AbandonedPublic

Authored by rcraik on Apr 20 2015, 10:44 AM.

Details

Reviewers
hfinkel
rsmith
Summary

According to the C11 standard, _Static_assert should be allowed as clause-1 in a for loop.

For example:

for (_Static_assert(1, "1 is nonzero");;) {}

The relevant section of the C11 grammar is:
for ( declaration expressionopt ; expressionopt ) statement
declaration:
declaration-specifiers init-declarator-listopt ;
static_assert-declaration

It is not allowed in C++11, where the for statement has the form:
for ( for-init-statement conditionopt; expressionopt) statement
and for-init-statement can only be an expression-statement or a simple-declaration, not a static_assert-declaration

Diff Detail

Event Timeline

rcraik updated this revision to Diff 24026.Apr 20 2015, 10:44 AM
rcraik retitled this revision from to Allow C11 static assert declaration as clause-1 in for loops..
rcraik updated this object.
rcraik edited the test plan for this revision. (Show Details)
rcraik added reviewers: rsmith, hfinkel.
rcraik updated this object.
rcraik added subscribers: Unknown Object (MLST), fraggamuffin.
rsmith edited edge metadata.Apr 20 2015, 3:06 PM

This seems much more likely to be a defect in C11 than a deliberate feature to me. Have you asked WG14 whether this was intentional?

This seems much more likely to be a defect in C11 than a deliberate feature to me. Have you asked WG14 whether this was intentional?

I asked the question and the consensus seems to be that it should not be allowed. The relevant thread is www.open-std.org/JTC1/SC22/WG14/13677

Thanks, then I think we can put this on hold for now. We can revisit it if the C committee decide that they do in fact want to allow this. (I also agree with one of the comments there, that the current wording can be read as saying that this is not allowed because a _Static_assert declaration declares something other than an identifier.)

rcraik abandoned this revision.Apr 23 2015, 7:38 AM