Andrew Tomazos
Andrew Tomazos

Reputation: 68658

C++11 name re-evaluation in completed scope of a class?

It says in C++ 3.3.7.2 [basic.scope.class]

A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S.

What is an example of a translation unit where a name N used in a class S refers to a different declaration in its context than when it is re-evaluated in the completed scope of S?

Upvotes: 5

Views: 233

Answers (1)

Andrew Tomazos
Andrew Tomazos

Reputation: 68658

struct X {};
struct Y {};

typedef X N;

struct S
{
    N n;
    typedef Y N;
};

$ g++ test.cpp 
9:15: error: declaration of ‘typedef struct Y S::N’ [-fpermissive]
4:11: error: changes meaning of ‘N’ from ‘typedef struct X N’ [-fpermissive]

Upvotes: 1

Related Questions