eonil
eonil

Reputation: 86075

const type to const alias in C++11

I am using Clang included in Xcode 4.6.2 (4H1003).

Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)

Currently my compiler doesn't make a compile error for this code.

using AA = int const;
static AA const aa  =   0;

Because I am not familiar with accurate C++11 specs, I can't know what is correct behavior.

  1. Error for double const keyword.
  2. const on using is not allowed.
  3. This is some special case.
  4. This is compiler bug.

What is expected behavior by standard?

Upvotes: 1

Views: 294

Answers (1)

Xeo
Xeo

Reputation: 131829

This was already allowed back with C++98 - cv-qualifiers can be introduced multiple times through typedef names and template parameters - they're simply collapsed. If this wasn't allowed, generic code would have a lot of problems. The same thing happens for references too.

§7.1.6.1 [dcl.type.cv] p1:

There are two cv-qualifiers, const and volatile. [...]
Redundant cv-qualifications are ignored. [ Note: For example, these could be introduced by typedefs.—end note ]

Upvotes: 4

Related Questions