Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static_assert in for-init-statement of the for statement

What prevents compilers from compiling a static_assert placed in for-init-statement of the for statement?

For example:

for(static_assert(true, ""); false; ); // error
like image 654
rahnema1 Avatar asked Sep 13 '16 16:09

rahnema1


1 Answers

Grammatically. A for loop is:

for ( init-statement; conditionopt ; expressionopt ) statement

where an init-statement is either an expression followed by a ; or a simple-declaration. A static_assert-declaration is neither of those things, hence it can't go there.

like image 169
Barry Avatar answered Sep 21 '22 16:09

Barry