【问题标题】:Why isn't this class specialization using a concept accepted?为什么不接受使用概念的此类专业化?
【发布时间】:2021-02-23 01:57:38
【问题描述】:

以下代码尝试使用概念对类进行部分特化并向特化添加方法,但被 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 接受,虽然这不能保证正确性。)

【问题讨论】:

    标签: c++ templates template-meta-programming c++20 c++-concepts


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多