Please see the following code:
template <class T>
struct X {
enum class E { e0 };
template <class U, E e>
struct Y {};
template <class U>
struct Y<U, E::e0> {
static int f() { return 0; }
};
};
int main() {
X<int>::Y<int, X<int>::E::e0>::f();
}
VC++ 15.7.5 generates an error message:
1> test.cpp
1> some_directory\test.cpp(15): error C2039: 'f': is not a member of 'X<int>::Y<int,X<int>::E::e0>'
1> some_directory\test.cpp(15): note: see declaration of 'X<int>::Y<int,X<int>::E::e0>'
1> some_directory\test.cpp(15): error C3861: 'f': identifier not found
However, GCC & Clang seem to accept this code.
Which one is correct?
EDIT
On older version of VC++ generates the following error message:
source_file.cpp(9): error C2754: 'X<T>::Y<U,>': a partial specialization cannot have a dependent non-type template parameter
source_file.cpp(12): note: see reference to class template instantiation 'X<T>' being compiled
source_file.cpp(16): error C2039: 'f': is not a member of 'X<int>::Y<int,X<int>::E::e0>'
source_file.cpp(16): error C3861: 'f': identifier not found
So I think the reason VC++ refuses to compile is that enum class E
is defined inside a template class. Indeed, the error disappears (both in the old version and the recent 15.7.5) if I move enum class E
outside X
.
Is this case really a case of partial specialization on a dependent non-type template parameter?