我在N3936(7.2.2条款)中读到“在范围枚举的声明中不应该省略可选标识符”,所以我尝试了下列代码 (其中嵌入的注释试图解释我的解释)与 GNU-G ++ 4.8.3和3.4.2铛不透明和匿名枚举声明如何符合标准的要求?
# include <iostream>
enum any : int; // unscoped opaque declaration :int required by the standard
enum : int {a} t; // unscoped anonymous declaration of t (:int not required)
enum any : int {b} u; // redlecaration of type "any" with one enumerator
enum class foo : char; // scoped opaque declaration "foo" required, :char NOT
enum class foo : char {a, b} Foo; // redeclaration of "foo" with 2
// enumerators. now :char REQUIRED
enum class : char {d} Enum; // scoped anonymous declaration of Enum
// wouldn't be disallowed?
int main()
{
t = a; // assignment to "t"
u = b; // assignment to "u"
Foo = foo::a; // assignment to "Foo"
Enum = decltype(Enum)::d; // allowed (??)
std::cout << static_cast<int>(t) << ' '
<< static_cast<int>(u) << ' '
<< static_cast<int>(Foo) << ' '
<< static_cast<int>(Enum) << std::endl;
}
铛拒绝的代码,并在枚举声明发出一条消息,错误表示“作用域枚举需要一个名称”;然而,GNU-g ++接受 它并执行在标准输出上放置四个零(正如预期的那样,一旦代码运行)。
注意铛问题进行进一步的错误时,枚举的名称为“d”是 改为“一”,那样的话,在这种情况下,错误地宣布枚举将 是未范围枚举名称为“”冲突与类型为“any”的同名 (至少这是我解释的读取 诊断)。相反,GNU-g ++也会接受(连贯地)Enum枚举器的名称“a” 。
那么,真相是什么?
谢谢。我没有发现这个错误。 – GSi 2015-02-09 09:28:37