为什么不接受使用概念的此类班级专业化?

时间:2020-11-11 04:43:51

标签: c++ templates template-meta-programming c++20 c++-concepts

以下代码尝试使用概念对某个类进行部分专业化,并在该专业化中添加方法,但被clang 11.0.0拒绝:

#include <concepts>

template <typename T> // note: previous template declaration is here
struct S {};

template <std::integral T>
struct S<T>
{
    void f();
};

template <std::integral T> // error: type constraint differs in template redeclaration
void S<T>::f()
{
}

clang给出错误消息:

<source>:14:16: error: type constraint differs in template redeclaration
template <std::integral T>
               ^
<source>:3:11: note: previous template declaration is here
template <typename T>

(请参阅https://godbolt.org/z/Wv1ojK)。为什么此代码错误?还是这是Clang中的错误? (FWIW,该代码已被gcc trunk和MSVC 19.28接受,尽管不能保证正确性。)

1 个答案:

答案 0 :(得分:2)

这绝对是CLANG错误。它已经归档-#48020