This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2480. Lookup for enumerators in modules

Section: 6.5.1  [basic.lookup.general]     Status: drafting     Submitter: Richard Smith     Date: 2021-02-12

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.”