rahnema1 rahnema1 - 1 year ago 64
C++ Question

static_assert in for-init-statement of the for statement

What prevents compilers from compiling a

placed in for-init-statement of the for statement?

For example:

for(static_assert(true, ""); false; ); // error

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download