<分区>
我正在尝试使用 GCC 5.4 ( online example ) 编译以下 C++14 代码:
template<typename T>
struct traits {
template<typename X>
static constexpr bool vect = true;
};
template<typename T1, typename T2>
constexpr bool all_vect = traits<T1>::template vect<T2>;
bool something() {
return all_vect<void, double>;
}
但是我得到了以下错误:
<source>: In instantiation of 'constexpr const bool all_vect<void, double>':
<source>:11:12: required from here
<source>:8:16: error: 'template<class X> constexpr const bool traits<void>::vect<X>' is not a function template
constexpr bool all_vect = traits<T1>::template vect<T2>;
^
<source>:8:16: error: 'vect<T2>' is not a member of 'traits<void>'
Compiler exited with result code 1
虽然我在 GCC 6.1 或更高版本或 clang 3.9 或更高版本中没有问题。但是我试过的所有版本的 GCC5 都是一样的。
我没有找到原因?通常,GCC5 应该是 C++14 功能完整的。
对于 GCC5 中仍然使用变量模板的这个问题,是否有简单的解决方法?我不想回到使用简单特征,因为我正在将我所有的特征转换为使用变量模板。