Title
Lookup for enumerators in modules
Status
open
Section
6.5.1 [basic.lookup.general]
Submitter
Richard Smith

Created on 2021-02-12.00:00:00 last changed 2 months ago

Messages

Date: 2021-02-12.00:00:00

According to 6.5.1 [basic.lookup.general] paragraphs 2-3,

...A declaration X precedes a program point P in a translation unit L if P follows X, X inhabits a class scope and is reachable from P, or else...

A single search in a scope S for a name N from a program point P finds all declarations that precede P to which any name that is the same as N (6.1 [basic.pre]) is bound in S.

These rules cause problems for finding enumerators when qualified by an exported name of its enumeration type, unlike a member of a class. For example:

  export module A;
  enum class X { x };
  enum Y { y };

  export module B;
  import A;
  export using XB = X;
  export using YB = Y;

  // client code
  import B;
  int main() {
    XB x = XB::x; // should be OK because definition of X is reachable, even
                  // though A is not imported
    YB y = YB::y; // similarly OK
    YB z = ::y;   // error, because y from module A is not visible
  }

It would seem that this problem could be addressed by changing “inhabits a class scope” to “does not inhabit a namespace scope.”

History
Date User Action Args
2021-02-12 00:00:00admincreate