https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98120

            Bug ID: 98120
           Summary: Multiple definitions (single TU) of explicit
                    specialization of member enumeration of a class
                    template
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davveston at gmail dot com
  Target Milestone: ---

[temp.expl.spec]/1.7[1] allows explicitly specializing a member enumeration of
a class template.

Although [temp.spec]/5.2[2] specifies that multiple definitions of an explicit
specialization in a program is ill-formed (referring to [basic.def.odr]) NDR,
multiple definitions within a single TU falls under [basic.def.odr]/1[3], as
e.g. an explicit specialization of a class template (for some set template
arguments) is a class; the latter is not NDR and violations of it should be
diagnosed.

Both GCC and Clang does so for multiple ODR-violating (within same TU) explicit
specializations of function templates, class templates, variable templates,
member functions of class templates, static data members of class templates,
and member classes of class templates. However, only Clang diagnoses it for
member enumerations of class templates:

// prog.cc
template <auto>
struct S { enum class E; };

template<>
enum class S<0>::E { ex };

template<>
enum class S<0>::E { ey };  // (C')
  // Clang only - error: redefinition of 'C<...>::E'

int main() {}


The above ill-formed program (arguably not NDR) is accepted by various GCC
versions for various C++ versions.

Demo for GCC 10.1.0 compiled with 

 g++ prog.cc -Wall -Wextra -std=c++17 

here: https://wandbox.org/permlink/B3GhCK4UqfIh36VH

---

Explicit specializations for member enumerations of class templates have some
other tickets where the root cause (of fix of the root cause) may be related,
e.g. bug 53815 and bug 61491.

---

References:

[1] https://timsong-cpp.github.io/cppwp/n4659/temp.expl.spec#1.7
[2] https://timsong-cpp.github.io/cppwp/n4659/temp.spec#5.2
[3] https://timsong-cpp.github.io/cppwp/n4659/basic.def.odr#1

Reply via email to