【发布时间】:2014-09-03 13:51:49
【问题描述】:
比较clang 3.4.2和gcc 4.9,下面的代码哪个正确?
#include <iostream>
template<typename T>
struct SelfRec {
static const int value = SelfRec<T>::value;
};
int main() {
std::cout << SelfRec<int>::value << std::endl;
return 0;
}
clang 打印 0,gcc 给出典型的达到模板最大深度错误。
【问题讨论】:
-
由于这可能是未定义的行为,它们都正确。
-
与
-std=c++03both of them cannot compile this code. -
有趣的是,如果我们将
value设为 C++14 变量模板,那么 clang starts to show compiler errors related to a template instantiation recursion.
标签: c++ templates recursion clang gcc4.9