c++ - 为什么不接受使用概念的此类特化?

标签 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 接受,尽管这不能保证正确性。)

最佳答案

这绝对是一个 CLANG 错误。已经备案 - #48020 .

关于c++ - 为什么不接受使用概念的此类特化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64601583/

相关文章:

c++ - 尝试使用 g++ 为 64 位 Windows 编译 .cpp

c++ - 在 OpenGL 中将深度渲染到纹理时出现奇怪的结果

c++ - 模板元编程 : "does not have integral or enumeration type"

c++ - 如何在模板元程序中做短路条件?

templates - PyCharm中自动填充文件 "creation"日期

c++ - 如何检查模板参数是否是具有给定签名的可调用对象

c++ - 单独的类文件错误?

c++ - 我是否正确计算了我的 FPS?

c++ - 捕获可变模板参数的模板参数

使用模板的 C++ 静态分派(dispatch)