【发布时间】:2016-03-10 07:42:42
【问题描述】:
考虑以下几点:
template<class T>
struct A
{
struct B
{} static const b;
};
// case 1
template<class T>
typename A<T>::B const A<T>::b;
// case 2
template<class T>
typename A<T>::B const A<T>::b{};
int main()
{
A<int> a;
a.b;
return 0;
}
案例1:
gcc 5.2 通过
msvc 2015 更新 1 次通过
clang 3.7 错误:
default initialization of an object of const type 'const typename A<int>::B' without a user-provided default constructor
案例2:
gcc 5.2 通过
clang 3.7 通行证:
msvc 2015 更新 1 错误:
error C2143: syntax error: missing ';' before '<end Parse>'
每种情况下哪个编译器是对/错的?
【问题讨论】:
-
有趣的问题;我在我的电脑上用 VS2015 试了一下,得到了相同的结果。案例 1 有效,案例 2 给出了相同的编译器错误。
-
案例1是CWG 253。案例 2 是 MSVC 错误(
= {}似乎适用于 MSVC)。
标签: c++ c++11 visual-c++ gcc clang