That's just not valid syntax. It is "forbidden" by the standard by virtue of not being a possible grammar production.
A declaration such as
constexpr bool b{};
is a simple-declaration and has the syntax decl-specifier-seq init-declarator-list(opt) ;
(see C++17 [dcl.dcl]/1). The keyword constexpr
is a decl-specifier, and so is bool
(although only some decl-specifiers have an effect on the type; bool
does, but constexpr
does not).
The rest of the declaration, b{}
, is an init-declarator, which consists of a declarator plus an optional initializer, which in this case is {}
. (See [dcl.decl]/1.) The declarator is b
. In general, a declarator must contain an identifier such as b
. See [dcl.decl]/4.
There is a similar grammar production called an abstract-declarator which lacks an identifier (See [dcl.name]/1). Abstract declarators are allowed in particular contexts, such as when writing down a type-id, or in a parameter-declaration-clause (function parameters are allowed to be unnamed). However, an init-declarator must contain a declarator, not an abstract-declarator.
There is no other grammar production that would match constexpr bool{};
either.
constexpr bool;
. I don't think this has anything to do with functions or side-effects.gcc error expected primary-expression before...
with google is unclear.constexpr;
is also fine! Even with/permissive-
. This should be clearly ill-formed. Andconstexpr bool{} constexpr;
gives me this not quite related error message: "<source>(2): error C2144: syntax error: 'int' should be preceded by ';'"