Typedef declarations can, whereas alias declarations cannot, be used as initialization statements?
The grammar for an init-statement is, for C++17, as follows:
init-statement:
expression-statement:
- expression_opt;
simple-declaration:
- decl-specifier-seq init-declarator-list_opt ;
- attribute-specifier-seq decl-specifier-seq init-declarator-list ;
- attribute-specifier-seq_opt decl-specifier-seq ref-qualifier_opt [ identifier-list ] initializer ;
[...]
A typedef declaration may be used as an init-statement, and e.g. the following is valid (C++17) code:
if (typedef int Foo; true) { (void)Foo{}; }
// ^^^^^^^^^^^^^^^ init-statement
switch(typedef int Foo; 0) { case 0: (void)Foo{}; }
// ^^^^^^^^^^^^^^^ init-statement
whereas an alias-declaration may not be used as an init-statement:
if (using Foo = int; true) { (void)Foo{}; }
// ^^^^^^^^^^^^^^^ error: expected expression
switch(using Foo = int; 0) { case 0: (void)Foo{}; }
// ^^^^^^^^^^^^^^^ error: expected expression
Afaics a typedef declaration is a valid simple-declaration as typedef
is a decl-specifier which is part of a decl-specified-seq which in turn, by itself, is a valid simple-declaration, whereas an alias-declaration is an entirely different declaration and not a simple-declaration.
Much like the answers in What is the difference between 'typedef' and 'using' in C++11?, I was always under the impression that alias declarations have the same semantics as and never falls short of typedef declarations, but as is apparent by the examples above (as of C++17?) it does, in use cases restricted to simple-declaration:s, particularly C++17 initialization statements (init-statement:s).
Question:
- Is it indeed a fact that a typedef declaration is a valid init-statement/simple-declaration whereas an alias declaration is not? Is this an intended "deviation" as of C++17 w.r.t. the previous (near-?)identical semantics of these two types of declarations?