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...
template<>
it becomes invalid for clang, but valid for gcc - godbolt.org/z/GGjjcnPMx – Menagerieenum
and put have something likeenum kind1_named; template <> struct foo<kind1> { using named = kind1_named; };
– Scarrow