First part:
I'm studying in some detail opaque-enum-declarations and elaborated-type-specifiers for a few days already, and I really would like somebody to confirm this. GCC and VS2013 don't compile this code (clang does) and I believe clang is in accordance with §7.1.6.3/1, as enum E
is an elaborated-type-specifier that is not the sole constituent of the declaration enum E e = E::b;
. Is my analysis correct?
#include <iostream>
enum class E : char {a = 'a', b};
int E;
enum E e = E::b; // Doesn't compile in GCC and VS2013
int main()
{
std::cout << (char)(e) << '\n';
}
Second part:
The snippet below, which is very similar to the one above, doesn't compile. I understand why it doesn't (the elaborated-type-specifier enum E
is the sole constituent of the declaration enum E;
and §7.1.6.3/1 doesn't allow this). What I'd like to know is why can't the compiler accept this construction?
#include <iostream>
enum class E : char {a = 'a', b};
int E;
enum E; // This doesn't compile.
E e = E::b;
int main()
{
std::cout << (char)(e) << '\n';
}