考虑以下代码片段:
我正在使用g++-4.9.2编译它,使用[-std=c++11 -O0 -g3 -pedantic -Wall -Wextra -Wconversion]并得到错误:'error: uninitialized const member in ‘struct Bar<Foo>’。这很明显。但是,尝试将std::string作为Foo成员添加,程序就可以编译了!
struct Foo {
};
template<typename T>
struct Bar {
const T foo;
};
int main() {
Bar<Foo> test;
}
我正在使用g++-4.9.2编译它,使用[-std=c++11 -O0 -g3 -pedantic -Wall -Wextra -Wconversion]并得到错误:'error: uninitialized const member in ‘struct Bar<Foo>’。这很明显。但是,尝试将std::string作为Foo成员添加,程序就可以编译了!
#include <string>
struct Foo {
std::string test;
};
// (...)
发生了什么?将测试的类型更改为double会导致程序再次无法编译。类中哪个字符串成员发生了变化?
自从4.6版本以来,gcc似乎就是这样的行为。