以下代码尝试使用概念对某个类进行部分专业化,并在该专业化中添加方法,但被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接受,尽管不能保证正确性。)