我编写了一个使用大量 C++11 元编程技术和 CRTP 的小型库,它可以很好地与 g++ 4.7.2 一起编译
现在,我尝试用 Intel icpc 13.0.0.079 编译它,它会产生数百个错误。所以我试图一个接一个地隔离问题。
所以,首先,考虑这段代码,它在 g++ 4.7.2 下编译没有问题
#include <iostream>
template<template<typename> class Crtp, typename Type>
struct Base {};
template<typename Type>
struct Derived : public Base<Derived, Type>
{
Derived(): Base<Derived, Type>() {;}
};
int main()
{
Derived<int> x;
return 0;
}
icpc 和 clang 都无法编译这段代码:
test_crtp.cpp(26): error: type "Derived<Type>::Derived" is not a class template
Derived(): Base<Derived, Type>() {;}
^
test_crtp.cpp(26): error: "Base" is not a nonstatic data member or base class of class "Derived<int>"
Derived(): Base<Derived, Type>() {;}
^
detected during instantiation of "Derived<Type>::Derived() [with Type=int]" at line 31
compilation aborted for test_crtp.cpp (code 2)
那么它是 intel 和 clang 还是 g++ 中的错误?如果它在 intel 和 clang 中,你认为它会在未来的版本中解决吗?