GCC部分专业化失败

时间:2017-06-23 07:19:35

标签: c++11 gcc c++14 template-specialization c++17

在回答this问题之后,我决定深入研究这个问题,找到一个同样错误的最小和可复制的例子。

假设我有以下主要模板,我想将其专门化为std::vector,如下所示:

#include <vector>
#include <iostream>

template<typename T, typename T::value_type v>
struct foo;

template<typename T, T v>
struct foo<std::vector<T>, v> {
    static constexpr T value = v;
};

int main() {
    std::cout << foo<std::vector<int>, 32>::value << std::endl;
    return 0;
}

GCC 7.1.0不会使用-std=c++11-std=c++14-std=c++1z编译上面的代码,而不是实验性GCC 8.0.0,只能使用-std=c++11-std=c++14。它们产生相同的错误输出:

prog.cc:8:12: error: partial specialization 'struct foo<std::vector<T>, v>' is not more specialized than [-fpermissive]
     struct foo<std::vector<T>, v> {
            ^~~~~~~~~~~~~~~~~~~~~~
prog.cc:5:12: note: primary template 'template<class T, typename T::value_type v> struct foo'
     struct foo;
            ^~~

本示例适用于GCC 6.3.0,至少适用于GCC 4.5.4。

有人可以确认这是编译器错误吗?是否有使用GCC 7.1.0的解决方法使我的示例有效?

0 个答案:

没有答案