Partial specialization failure with GCC

a 夏天 提交于 2021-01-28 06:03:45

问题


After answering this question I decided to dig deeper in the issue to find a minimal and replicable example with same error.

Let assume I have the following primary template and I would like to specialize it to std::vector as follows:

#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 won't compile the code above with -std=c++11, -std=c++14 or -std=c++1z neither the experimental GCC 8.0.0 but only with -std=c++11 or -std=c++14. They produce the same error output:

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;
            ^~~

The presented example works well with GCC 6.3.0 and at least with GCC 4.5.4.

Could anyone confirm that this is a compiler bug? Is there any workaround with GCC 7.1.0 to make my example work?

来源:https://stackoverflow.com/questions/44715375/partial-specialization-failure-with-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!