继承模板函数重载决议: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
相关产品推荐
相关产品推荐

