Nat*_*eed 7 c++ templates template-meta-programming c++-concepts c++20
以下代码尝试使用概念对类进行部分特化,并向特化添加方法,但被 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()
{
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
(参见https://godbolt.org/z/Wv1ojK)。为什么这段代码是错误的?或者这是clang中的一个错误?(FWIW,此代码被 gcc trunk 和 MSVC 19.28 接受,尽管这不能保证正确性。)