Reputation: 1185
[dcl.spec]/3 in c++1z (emphasis is mine):
If a type-name is encountered while parsing a decl-specifier-seq, it is interpreted as part of the decl-specifier-seq if and only if there is no previous defining-type-specifier other than a cv-qualifier in the decl-specifier-seq. The sequence shall be self-consistent as described below. [ Example:
typedef char* Pc; static Pc; // error: name missing
Here, the declaration
static Pc
is ill-formed because no name was specified for the static variable of typePc
. To get a variable calledPc
, a type-specifier (other thanconst
orvolatile
) has to be present to indicate that the typedef-namePc
is the name being (re)declared, rather than being part of thedecl-specifier
sequence.
Nevertheless, the snippet below doesn't compile in g++ and clang. Why is that?
typedef char* Pc;
static int Pc;
Upvotes: 2
Views: 97
Reputation: 3396
The intent of the paragraph is to show that typedef char* Pc
is valid, whereas static Pc
is not, not that you can redeclare Pc
as something else (in the same scope). In other words, static Pc
and static int Pc
are not different entities. Nothing's changed that would allow you to do this.
Given a set of declarations in a single declarative region, each of which specifies the same unqualified name,
(4.1) — they shall all refer to the same entity, ...
Upvotes: 3