【发布时间】:2022-01-22 12:37:47
【问题描述】:
此代码有效吗?
template<bool b>
struct s {
void f() const {
}
static void f() requires b {
}
};
void g() {
s<true>().f();
}
clang 说是,但 gcc 说不是
<source>: In function 'void g()':
<source>:10:20: error: call of overloaded 'f()' is ambiguous
10 | s<true>().f();
| ~~~~~~~~~~~^~
<source>:3:14: note: candidate: 'void s<b>::f() const [with bool b = true]'
3 | void f() const {
| ^
<source>:5:21: note: candidate: 'static void s<b>::f() requires b [with bool b = true]'
5 | static void f() requires b {
| ^
Compiler returned: 1
【问题讨论】:
-
让非
static成员void f() const requires(!b)怎么样? -
我相当肯定 gcc 是对的,而 clang 是错的,但是从标准中挖掘一个权威引用将是一件很困难的事情。
-
@TedLyngmo,是的,我可以这样做,但这会导致我在 clang 中的总编译时间显着降低。
-
@DavidStone 哦,不好。顺便说一句,clang 选择了哪个重载?编辑:我检查了。这是有约束的。
标签: c++ language-lawyer c++20 c++-concepts