More than one listing declaration

There is a quote from sec. 3.3.1 / 4 of the working draft N3797:

Given a set of ads in a single declarative region, each of which indicates the same unqualified name,

- exactly one declaration declares a class name or an enumeration name that is not a typedef name, and other declarations must refer to the same variable or enumerator, or all relate to functions and function templates;

We can declare a type name enumseveral times in one declarative scope:

enum A; // declared first time, the other declaration with the same
        // unqualified name shall all refer to the same variable or enumeration.
enum A; // This and the other declarations shall all refer to the that enumeration
extern int A; // Fail, now enum A is hidden and we can access it
              // via elaborated-type-specifier only

I'm confused. Can you explain this behavior? I would like to find relevant links to the current working draft.

+4
source share
2

n3797 3.3.1/4:

, ,

- , ;

- , , ; .

, , . . S7.2 , :

enum A : int; // declaration (and it is an enumeration name)
enum A : int; // refers to the same entity

enum struct A; // declaration (and it is an enumeration name)
enum struct A; // refers to the same entity

enum A {}; // declaration (and it is an enumeration name)
enum A {}; // refers to the same entity

.

extern int A; // declaration hides enumeration name

void f() {
  A j = A.a; // illegal. A is hidden
  int k = A; // legal
}

. n3797 3.3.10/2:

(9.1) (7.2) , , , . , , ( ) , , , , .

, A . , ?


: ? , , , , A? - . S7.2/6 :

, , (3.3.2) enum-base ( ), . , , } , .

, A , . 7.2/3 :

opaque-enum , . [: , opaque-enum, . enumspecifier. -end note] . , , , .

, , , , , , .

, , , , .

+2

, . (enum) - ,    enum A;
  , . . 1. :
enum A { a, b, c };
, 3 {a, b, c}, - , - A. :
              enum NAME; NAME var1; NAME var2;
:
enum { a, b, c };
, , , ..

0

Source: https://habr.com/ru/post/1540949/


All Articles