Should this be ambiguous or not? (implicit casts)

荒凉一梦 提交于 2019-12-03 09:37:57

Yes, the expected result is Ambiguity to the best of my interpretation of Clause 13.3.3.2

Matching argument 'v' of type 'B' to the parameters of either of the overloaded constructors of 'A' requires a user defined conversion. There both the sequences are of CONVERSION rank.

My interpretation is that the following quote from $13.3.3.2 applies

[...]User-defined conversion sequence U1 is a better conversion sequence than another user-defined conversion sequence U2 if they contain the same user-defined conversion function or constructor and if the second standard conversion sequence of U1 is better than the second standard conversion sequence of U2.

Both of these invoke different conversion functions in class 'B'. Therefore, I think the first condition itself is not satisfied and hence the expected result is Ambiguity as nither of the conversion sequences is better than the other.

Disclaimer : the standard is really complex on these parts, so I may be completely wrong in my understanding.

Standard definition of the best viable function (13.3.3) :

Given these definitions, a viable function F1 is defined to be a better function than another viable function F2 if for all arguments i, ICSi(F1) is not a worse conversion sequence than ICSi(F2), and then

[...]

  • the context is an initialization by user-defined conversion (see 8.5, 13.3.1.5, and 13.3.1.6) and the standard conversion sequence from the return type of F1 to the destination type (i.e., the type of the entity being initialized) is a better conversion sequence than the standard conversion sequence from the return type of F2 to the destination type.

If I understand correctly, the type of the object being constructed has its importance here, and that would make A::A(const A &) a better candidate.


Refer to Johannes comments to see why this answer is incorrect : this is indeed ambiguous for the reason pointed out by Chubsdad.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!