带约束的函数重载解析:调用f()是否存在歧义?
调用函数模板f()是否存在歧义?
我认为调用f()不应存在歧义,因为其中一个函数的约束更强。但GCC 12.2和Clang trunk拒绝编译这段代码,而Clang 15、MSVC 19.33和MSVC trunk则可以正常通过编译。
代码示例
template<typename...> int f(); template<typename = void> int f() requires true; static_assert(sizeof(f()));
GCC编译错误信息
<source>:7:23: error: call of overloaded 'f()' is ambiguous 7 | static_assert(sizeof(f())); | ~^~ <source>:2:5: note: candidate: 'int f() [with <template-parameter-1-1> = {}]' 2 | int f(); | ^ <source>:5:5: note: candidate: 'int f() requires true [with <template-parameter-1-1> = void]' 5 | int f() requires true; | ^
内容的提问来源于stack exchange,提问作者303
相关产品推荐
相关产品推荐

