0

According to cppreference, both gcc and msvc have completed the implementation of C++20 feature using enum, which means we can using-declaration with an enum:

struct A { 
  enum e { /* ... */ }; 
};

struct S { 
  using enum A::e;
};

But when I apply it to the templates:

template <class T>
struct S { 
  using enum T::e;
};

gcc rejects it with:

<source>:7:14: error: 'using enum' of dependent type 'typename T::e'
    7 |   using enum T::e;
      |              ^~~~
<source>:7:17: note: declared here
    7 |   using enum T::e;
      |                 ^

msvc also rejects it with:

<source>(7): error C2868: 'e': ill-formed using-declaration; expected a qualified-name
<source>(8): note: see reference to class template instantiation 'S<T>' being compiled

I have no idea why this cannot work since it seems to be no different from non-templates.

Is this a compiler bug or just ill-formed?

康桓瑋
  • 33,481
  • 5
  • 40
  • 90

1 Answers1

0

From the proposal:

The elaborated-enum-specifier shall not name a dependent type and the type shall have a reachable enum-specifier.

In your example T::e is a dependent type.

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185