[英]What's the difference between an explicit call and an implicit call of the conversion function?
Consider this example:考虑这个例子:
struct A{
template<class T>
operator T(); // #1
};
struct B:A{
template<class U>
operator U&&(); // #2
};
int main(){
B b;
int a = b; // #3
b.operator int(); // #4
}
According to [class.member.lookup] p7根据 [class.member.lookup] p7
If N is a non-dependent conversion-function-id, conversion function templates that are members of T are considered.如果 N 是非依赖转换函数 ID,则考虑作为 T 成员的转换 function 模板。 For each such template F, the lookup set
S(t,T)
is constructed, considering a function template declaration to have the namet
only if it corresponds to a declaration of F ([basic.scope.scope]).对于每个这样的模板 F,构造查找集S(t,T)
,考虑 function 模板声明只有当它对应于 F 的声明([basic.scope.scope])时才具有名称t
。 The members of the declaration set of each such lookup set, which shall not be an invalid set, are included in the result.结果中包括每个此类查找集的声明集的成员,这些成员不应是无效集。
#1
and #2
are both included in the lookup result regardless of what the conversion-function-id s are in #3
and #4
. #1
和#2
都包含在查找结果中,而不管#3
和#4
中的conversion-function-id是什么。 The diagnosis for #3
is what we expect, in other words, both #1
and #2
are candidates and they are indistinguishable. #3
的诊断是我们所期望的,换句话说, #1
和#2
都是候选者,并且无法区分。
However, it seems that implementations only consider #2
as the unique candidate when processing #4
.但是,在处理#4
时,实现似乎只将#2
视为唯一候选者。 As said above, the candidate set should be the same for either #3
or #4
.如上所述, #3
或#4
的候选集应该相同。 Do I omit some other rules that cause the difference?我是否忽略了其他一些导致差异的规则? Or, Is it a bug in implementations?或者,它是实现中的错误吗?
Implementations just haven't caught up to the new(ly clarified) rules, which had to be largely invented in 2020 since no published standard version has ever described lookup for conversion function templates in any sensible way.实施只是没有跟上新的(已澄清的)规则,这些规则必须在 2020 年大量发明,因为没有发布的标准版本以任何合理的方式描述转换 function 模板的查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.