Forward-declaration of enum member of template-specialization - fails with GCC

Viewed 75

I know that, generally, we can forward-declare enums in C++11.

So, why does this:

enum kind_t { kind1, kind2 };

template <kind_t Kind> struct foo {};

template <> struct foo<kind1> {
    enum named : int;
};

enum foo<kind1>::named : int {
    named1 = 123,
    named2 = 456,
};

fail to compile with GCC (12.1)? The error is (Godbolt):

<source>:9:6: error: cannot add an enumerator list to a template instantiation
    9 | enum foo<kind1>::named : int {
      |      ^~~~~~~~~~
ASM generation compiler returned: 1
<source>:9:6: error: cannot add an enumerator list to a template instantiation
    9 | enum foo<kind1>::named : int {
      |      ^~~~~~~~~~

This seems to compile fine with clang++ 14.0...

0 Answers
Related