You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexpr is a declaration specifier, but not a cv qualifier, thus may appear in the decl-specifier-seq, but not in the declarator; in other words, for the purposes of variable declarations, it's the same grammatical animal as static, although it has an influence on the type.
These gory details mean that the following compiles, and the commented-out line is indeed erroneous (and yes, U+066D ARABIC FIVE POINTED STAR (٭) is allowed in identifiers).
In other words, replacing constexpr by const or vice-versa in a correct variable declaration may yield an ungrammatical declaration, or a correct declaration with a different type, since constexpr applies constness at the top level.
Decision.
Write constexpr initially.
For constexpr member variables, write static constexpr rather than constexpr static.
The following still stand:
Keep cv-qualifiers that are part of the decl-specifier-seq at the end of the decl-specifier-seq, and the same for type-specifier-seq: T const rather than const T.
Omit redundant specifiers: final const on constexpr variables, static on declarations at namespace scope, inline on constexpr functions and constructors*.
constexpr
is a declaration specifier, but not acv
qualifier, thus may appear in thedecl-specifier-seq
, but not in thedeclarator
; in other words, for the purposes of variable declarations, it's the same grammatical animal asstatic
, although it has an influence on the type.These gory details mean that the following compiles, and the commented-out line is indeed erroneous (and yes, U+066D ARABIC FIVE POINTED STAR (٭) is allowed in identifiers).
In other words, replacing
constexpr
byconst
or vice-versa in a correct variable declaration may yield an ungrammatical declaration, or a correct declaration with a different type, sinceconstexpr
applies constness at the top level.Decision.
Write
constexpr
initially.For
constexpr
member variables, writestatic constexpr
rather thanconstexpr static
.The following still stand:
Keep
cv
-qualifiers that are part of thedecl-specifier-seq
at the end of thedecl-specifier-seq
, and the same fortype-specifier-seq
:T const
rather thanconst T
.Omit redundant specifiers: final
const
onconstexpr
variables,static
on declarations at namespace scope,inline
onconstexpr
functions and constructors*.Example:
* See the standard, 7.1.5(2). ↩
The text was updated successfully, but these errors were encountered: