Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 867
Andrew Tomazos Avatar asked Nov 13 '22 05:11

Andrew Tomazos


1 Answers

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]
like image 145
Andrew Tomazos Avatar answered Nov 14 '22 22:11

Andrew Tomazos