Consider a templated entity, say (A) a function template, and (B) a member enum of a class template.
// (A)
template<auto>
int f();
// (B)
template <auto>
struct T { enum class E; };
Is an implementation required to diagnose ODR-violations due to duplicated definitions of the same explicit specialization of such a template entity? Or, in other words, does [basic.def.odr]/1 apply for explicit specializations?
As an example GCC and Clang both diagnoses the following program as ill-formed:
// Single translation unit;
// primary template of 'f' declared as in (A) above.
template<>
int f<0>() { return 0; }
template<>
int f<0>() { return 1; }
// GCC & Clang - error: redefinition of 'int f() [with auto <anonymous> = 0]'
whereas only Clang diagnoses the follow program as ill-formed, whilst GCC accepts it:
// Single translation unit;
// primary template of 'T' defined as in (B) above.
template<>
enum class T<0>::E { ex };
template<>
enum class T<0>::E { ey };
// Clang only - error: redefinition of 'E'
Ill-formed NDR, or ill-formed? (/both compilers correct, or GCC bug?)
Tested on various GCC and Clang versions, for -std=c++17
and -std=c++2a
, with the same result