为什么不接受使用概念的这种课程专业化?

Why isn't this class specialization using a concept accepted?

本文关键字:专业化 不接受 为什么      更新时间:2024-09-23

以下代码试图使用概念部分专门化一个类,并在专门化中添加一个方法,但被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)。为什么这个代码是错误的?或者这是叮当声中的一只虫子?(FWIW,这个代码被gcc trunk和MSVC 19.28接受,尽管这不能保证正确性。(

这绝对是一个CLANG错误。它已经被归档了——#48020。