枚举的声明点
Point of declaration for an enumeration
声明枚举类型有什么意义?它紧跟在枚举名称之后吗?我看到了标准 C++ 14 (n4296) §3.3.2/3:
The point of declaration for an enumeration is immediately after the
identifier (if any) in either its enum-specifier (7.2) or its first
opaque-enum-declaration (7.2), whichever comes first
但是当我尝试重现它时;
template <class T>
struct CL
{
using UndType = int;
};
enum class E: CL<E>::UndType; //error: E is undefined
尽管 enum-base 用于枚举 E
位于标识符之后并且必须可见,但我在所有编译器上都遇到了错误。
以下;
enum class E : CL<E>::UndType;
在当前的某些实现(经过测试的 clang++、g++ 和 MSVC)中不被接受为有效声明。他们不接受 enum-base CL<E>::UndType
中尚未完成的类型 E
。在测试的实现中给出的错误是 E
是 undeclared 在这一点上。他们似乎将声明点放在 enum-base 的末尾,他们认为它一旦完成就被声明。
阅读规范时;
§14.3.1/2 模板类型参数
[ Note: A template type argument may be an incomplete type (3.9). — end note ]
和
§7.2/6 枚举声明
An enumeration whose underlying type is fixed is an incomplete type from its point of declaration (3.3.2) to immediately after its enum-base (if any), at which point it becomes a complete type.
是否暗示它是可编译的;与 CRTP 实现的情况一样。
我确定这(即编译失败 enum class E : CL<E>::UndType;
)是有意为之还是被视为用例。从规范来看,不透明的枚举声明被给予了一些 "special" 处理 w.r.t。它的基类型和它必须是整数类型的要求。
据推测,代码 应该是可编译的 给定 CWG#1482 的分辨率。
至于当前的解决方法...
这个;
enum class E; // default underlying type is int
是最小申报。
不透明的声明可以是;
enum class E : int; // int base
以下是完整定义(包括枚举数);
enum class E : int {/*...*/};
或者要使用 class 模板,可以使用另一种类型(可能 void
)。
enum class E : CL<void>::UndType;
现在 CWG2516 为此开放。
我认为这是标准中的一个错误,它禁止 is_scoped_enum
.
的可移植实现
声明枚举类型有什么意义?它紧跟在枚举名称之后吗?我看到了标准 C++ 14 (n4296) §3.3.2/3:
The point of declaration for an enumeration is immediately after the identifier (if any) in either its enum-specifier (7.2) or its first opaque-enum-declaration (7.2), whichever comes first
但是当我尝试重现它时;
template <class T>
struct CL
{
using UndType = int;
};
enum class E: CL<E>::UndType; //error: E is undefined
尽管 enum-base 用于枚举 E
位于标识符之后并且必须可见,但我在所有编译器上都遇到了错误。
以下;
enum class E : CL<E>::UndType;
在当前的某些实现(经过测试的 clang++、g++ 和 MSVC)中不被接受为有效声明。他们不接受 enum-base CL<E>::UndType
中尚未完成的类型 E
。在测试的实现中给出的错误是 E
是 undeclared 在这一点上。他们似乎将声明点放在 enum-base 的末尾,他们认为它一旦完成就被声明。
阅读规范时;
§14.3.1/2 模板类型参数
[ Note: A template type argument may be an incomplete type (3.9). — end note ]
和
§7.2/6 枚举声明
An enumeration whose underlying type is fixed is an incomplete type from its point of declaration (3.3.2) to immediately after its enum-base (if any), at which point it becomes a complete type.
是否暗示它是可编译的;与 CRTP 实现的情况一样。
我确定这(即编译失败 enum class E : CL<E>::UndType;
)是有意为之还是被视为用例。从规范来看,不透明的枚举声明被给予了一些 "special" 处理 w.r.t。它的基类型和它必须是整数类型的要求。
据推测,代码 应该是可编译的 给定 CWG#1482 的分辨率。
至于当前的解决方法...
这个;
enum class E; // default underlying type is int
是最小申报。
不透明的声明可以是;
enum class E : int; // int base
以下是完整定义(包括枚举数);
enum class E : int {/*...*/};
或者要使用 class 模板,可以使用另一种类型(可能 void
)。
enum class E : CL<void>::UndType;
现在 CWG2516 为此开放。
我认为这是标准中的一个错误,它禁止 is_scoped_enum
.