Reputation:
I have some C++ code that takes the following form:
template <typename type>
class foo
{
type a;
class bar;
};
template <typename type>
class foo<type>::bar
{
enum class baz;
};
template <typename type>
enum class foo<type>::bar::baz
{
val1,
val2
};
With this code, I'm trying to get the enum class to be accessible by methods inside foo::bar and to be able to store data of the type of this enum class. The enum class is also not meant to be of a template type - the enum class enumerators are integers/the default type of an enum class.
However, when I compile this is MinGW/Code::Blocks this seems to produce two error message, both on the line:
enum class foo<type>::bar::baz
error: template declaration of 'enum baz'
error: foo<type>::bar has not been declared
Upvotes: 1
Views: 459
Reputation: 15941
I think this is almost certainly a compiler bug. Based on temp.mem.class and temp.mem.enum, I'd say this should definitely be valid C++. clang as well as icc seem to compile this code just fine. GCC (MinGW is basically GCC) as well as MSVC apparently fail to compile this, however. It seems both compilers (even in their most recent versions) mistake this definition of an enum member of a class template for an attempt to declare an enum template (which would indeed be illegal)…
Edit: In case of MSVC, there seems to already be an open issue here
Upvotes: 2