Static data item array binding evaluation scale

I was about to file a bug against GCC, but then realized that if my interpretation of the Standard is correct, it is a defect in the host language, not a compiler bug.

When a static data member of an array type is defined outside of the class scope, identifiers on the array boundary are looked up in the class scope.

§9.4.2 [class.static.data] says "The initialization expression in the definition of a static data member falls within the scope of its class (3.3.7)", but says nothing about the declarator itself. This seems to be the only context for looking up the name in the declarator.

§8.4.2 [dcl.array] does not mention the scope of the array, so by default the expression is evaluated in the enclosing scope, which is the namespace.

class X {
  static int const size = some_complicated_metafunction<>::value;
  static int arr[ size ];
};

// "size" should be qualified as "X::size", which is an access violation.
int X::arr[ size ] = {};

      

The problem is that if the array binding is not evaluated in the class scope, there is no access to the private members of the class, but some_complicated_metafunction<>

must be considered. An array constraint requires the same scope as an initializer, for essentially the same reason as an initializer. (Not as much, though, since constant expressions can always be recalculated, unlike a private object address.)

Am I missing something or was DR ok?

+3


source to share


1 answer


I think the array associated in the member definition is in the class. Standard 3.3.7 / 1:

The following rules describe the scope of names declared in classes.

...

5) Potential declaration scope that continues before or after the end of a class definition also extends to the regions defined by its member definitions, even if members are defined lexically outside the class (this includes static data definitions, nested class definitions, member function definitions (including body member functions and any part of the declarative part of such definitions that follows the identifier-identifier , including the parameter-declaration-clause and any default arguments (8.3.6) ....



Here is the ad ID X::arr

.

+4


source







All Articles