对于调用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;
| ^
[temp.func.order]/6.1
中所述的参数列表长度要求。因此,似乎Clang 10-15
和MSVC 19
都不应该接受这段代码。而Clang trunk
也拒绝了它,这似乎也强调了这个观点。 - 303