为什么这个 class 专业化没有使用公认的概念?
Why isn't this class specialization using a concept accepted?
以下代码尝试使用概念部分特化 class 并向特化添加方法,但被 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 接受,尽管这不能保证正确性。)
这绝对是一个 CLANG 错误。它已经归档 - #48020.
以下代码尝试使用概念部分特化 class 并向特化添加方法,但被 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 接受,尽管这不能保证正确性。)
这绝对是一个 CLANG 错误。它已经归档 - #48020.