Talk:cpp/language/static assert

ok they say:

"A static assert declaration may appear at namespace and block scope (as a block declaration) and inside a class body (as a member declaration) "

But on my GCC 5.1.0 it works also on global scope. Is the above text correct/complete? Or is it just a silent feature enabled on my gcc compiler.

I my own eyes static_assert would make most sense on global scope anyway.

212.238.237.61 10:10, 3 September 2017 (PDT)
 * Global scope is a kind of namespace scope. T. Canens (talk) 12:18, 3 September 2017 (PDT)

This page doesn't appear to mention that the behaviour changes based on whether it contains a dependent parameter or not. E.g. the following will always (or can? - maybe compiler-dependent) assert, even if the function is never instantiated:

template  static int Foo {   static_assert (false); }

The following will only assert if the function is instantiated:

template constexpr bool False = false; template  static int Foo {   static_assert (False); }

Thanks to Jonathan Caves (MS) for pointing this out.


 * That's a templates quirk rather than a quirk. Note that both examples are equally ill-formed, just the second doesn't require a diagnostic  --Ybab321 (talk) 10:40, 20 February 2022 (PST)


 * we do mention this "dependent false" problem at cpp/language/if, which is where it often comes up in real life, but a similar note on static asserts inside templates could be worth it here, too. --Cubbi (talk) 11:18, 20 February 2022 (PST)