为什么不接受使用概念的此类班级专业化? [英] Why isn't this class specialization using a concept accepted?

查看:42
本文介绍了为什么不接受使用概念的此类班级专业化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码尝试使用概念对某个类进行部分专业化,并在该专业化中添加方法,但被clang 11.0.0拒绝:

The following code attempts to partially specialize a class using a concept and add a method to the specialization, but it is rejected by 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给出错误消息:

clang gives the error message:

<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接受.)

(see https://godbolt.org/z/Wv1ojK). Why is this code wrong? Or is this a bug in clang? (FWIW, this code is accepted by gcc trunk and by MSVC 19.28, although that's no guarantee of correctness.)

推荐答案

这绝对是CLANG错误.它已经归档-#48020 .

This is definitely a CLANG bug. It is already filed - #48020.

这篇关于为什么不接受使用概念的此类班级专业化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆