The following paragraph is taken from [dcl.typedef]:
Within the scope of its declaration, a typedef-name is syntactically equivalent to a keyword and names the type associated with the identifier in the way described in Clause 8. A typedef-name is thus a synonym for another type. A typedef-name does not introduce a new type the way a class declaration (9.1) or enum declaration does.
The other relevant passage we need is from [dcl.type]
As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailing-type-specifier-seq. The only exceptions to this rule are the following: … long can be combined with long.
In the following code, i1
is just a synonym for long.
typedef long i1;
typedef long i1 i2;
Thus, I expect the second line to be understood as typedef long long i2
. However, MSVC2015RC fails with
Error C2146 syntax error: missing ';' before identifier 'i2'
Can anyone point to the part of the standard that invalidates my expectation?
UPDATE
My point is that, as far as I understand the grammar in [dcl.type],
type-specifier:
trailing-type-specifier
class-specifier
enum-specifier
trailing-type-specifier:
simple-type-specifier
elaborated-type-specifier
typename-specifier
cv-qualifier
type-specifier-seq:
type-specifier attribute-specifier-seq opt
type-specifier type-specifier-seq
trailing-type-specifier-seq:
trailing-type-specifier attribute-specifier-seq opt
trailing-type-specifier trailing-type-specifier-seq
a decl-specifier-seq does allow for a sequence of type specifiers as long as they satisfy the combination rules. It seems to me that a type is not the same as a type-specifier even though a type is specified by a type specifier ;-)
Alright, I'll answer.
First, looking at this:
a typedef-name is syntactically equivalent to a keyword
This only means that typedef-names follow the syntax of keywords. This does not mean that a typedef-name is equivalent to any particular keyword. It's like a new, unique keyword.
Then we have,
A typedef-name is thus a synonym for another type.
So, given typedef long i1;
, what is this "another type"? It is long int
, not just long
.
In addition, what is a "type"? At the least, type-specifier is not a type. The type-specifier long
represents the type "long int" (see Table 10 of n3337 or Table 9 of n4296).
I'll copy my comment here:
i1
is a synonym for the type that islong int
. It is not a synonym for the keywordlong
. Otherwise you could also sayi1 double
and get along double
.
Though perhaps I should have said, i1
is not a synonym for the type-specifier long
, but it is a synonym for the type long int
.