Skip to content

[C++] Accessing enumerators from a scoped member enum through operator . triggers an error #113844

Open
@TheCalligrapher

Description

@TheCalligrapher

Here's the code sample that demonsrates the problem

struct S
{
  enum T { A };
  enum class U { B };
};

int main()
{
  S s;

  S::A;    // OK
  S::T::A; // OK
  S::U::B; // OK

  s.A;     // OK
  s.T::A;  // OK
  s.U::B;  // Error???
}

All six lines that refer to enumerators from enums declared inside class S are perfectly valid. However, Clang issues an error

error: 'S::U::B' is not a member of class 'S'
   17 |   s.U::B;  // Error???
      |     ~~~^

for last one (i.e. s.U::B). Why?

What makes it especially weird is that Clang has no problems with the qualified name in the s.T::A line, i.e. it does allow one to optionally use a qualified name to access enumerators from a "classic" unscoped enum (using qualified name with such enums is a possibility since C++11). However, for some unknown reason Clang rejects a similar attempt to access an enumerator from a scoped enum.

GCC and MSVC++ have no issues with such code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions