在 class 定义中使用 extern decl-specifier 的程序
Program with extern decl-specifier in a class definition
考虑以下程序:
extern class A;
int main() {}
根据 c++ 标准,这是格式正确的吗?如果格式错误,是否需要诊断?对于不同的编译器,我得到不同的结果:
- Clang:没有编译器错误(只有警告):http://melpon.org/wandbox/permlink/lhb8XNU01IyVhMnc
- GCC:编译器错误:http://melpon.org/wandbox/permlink/mIH9qmNY4noI1sEc
- Visual c++:没有编译器错误(只有警告):http://webcompiler.cloudapp.net/
根据 §7.1.1/1,程序格式错误:
If a storage-class-specifier appears in a decl-specifier-seq, […]
the init-declarator-list of the declaration shall not be empty
(except for an anonymous union declared in a named namespace or in the
global namespace, which shall be declared static
(9.5)).
考虑以下程序:
extern class A;
int main() {}
根据 c++ 标准,这是格式正确的吗?如果格式错误,是否需要诊断?对于不同的编译器,我得到不同的结果:
- Clang:没有编译器错误(只有警告):http://melpon.org/wandbox/permlink/lhb8XNU01IyVhMnc
- GCC:编译器错误:http://melpon.org/wandbox/permlink/mIH9qmNY4noI1sEc
- Visual c++:没有编译器错误(只有警告):http://webcompiler.cloudapp.net/
根据 §7.1.1/1,程序格式错误:
If a storage-class-specifier appears in a decl-specifier-seq, […] the init-declarator-list of the declaration shall not be empty (except for an anonymous union declared in a named namespace or in the global namespace, which shall be declared
static
(9.5)).