You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

继承模板函数重载决议:MSVC拒绝合法调用的C++20标准依据问询

C++20中using声明引入基类函数后的重载决议问题

我原本认为通过using b::f声明,基类的f(std::integral auto)会被纳入派生类d的f重载集中,因此f(signed{})的调用应该能在重载决议中被正常解析。而f(unsigned{})可以正常通过编译,是因为std::unsigned_integral是std::integral的更严格约束,派生类的f(std::unsigned_integral auto)会被优先选中。但MSVC明确拒绝了这段代码,想知道C++20标准中哪一款项支持f(signed{})的调用被解析?

代码示例

#include <concepts>

struct b { void f(std::integral auto); };
struct d : b { using b::f; void f(std::unsigned_integral auto); };

static_assert(requires { d{}.f(signed{}); }); // clang、gcc编译通过,MSVC失败
static_assert(requires { d{}.f(unsigned{}); }); // 所有编译器都通过

MSVC错误信息

<source>(6): error C2672: 'd::f': 找不到匹配的重载函数
<source>(4): note: 可能是'void d::f(_T0)'
<source>(6): note: 关联约束未满足
<source>(4): note: 概念'std::unsigned_integral<signed int>'计算结果为false
C:/data/msvc/14.38.33133/include\concepts(76): note: 约束未满足
<source>(6): error C2607: 静态断言失败

内容的提问来源于stack exchange,提问作者303

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 07:03:29