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 this is just ill-formed?
If I put using-declaration inside a member function:
template <class T>
struct S {
void f() {
using enum T::e;
}
};
then msvc accepts it, but gcc still rejects it with the same error message. Is there a difference compared to the first?
If this is just a common bug, according to temp.variadic#5.2:
Pack expansions can occur in the following contexts:
- In a using-declaration ([namespace.udecl]); the pattern is a using-declarator.
Does this mean that the following case is well-formed even if gcc and msvc do not accept it currently?
template <class... Ts>
struct S {
using enum Ts::e...;
};
Source: Windows Questions C++