Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


1895. Deleted conversions in conditional operator operands

Section:7.6.16  [expr.cond]    Status:CD4    Submitter:Richard Smith    Date:2014-03-17

[Adopted at the February, 2016 meeting.]

In an example like,

  struct B;  struct A { A(); A(B&) = delete; operator B&(); };  struct B : A {} b;  B &c = true ? A() : b;

the rules of 7.6.16 [expr.cond] paragraph 3 make thisambiguous:A() can be implicitly converted to the type“lvalue reference toB,” andb satisfies theconstraints to be converted to anA prvalue (it's of a typederived fromA and the cv-qualifiers are okay). Bullet 3 bullet 1is clear that we do not actually try to create anA temporaryfromb, so we don't notice that it invokes a deleted constructorand rule out that conversion.

If the deleted conversion is in the other sense, the result isunambiguous:

  struct B;  struct A { A(); A(B&); operator B&() = delete; };  struct B : A {} b;  B &c = true ? A() : b;

A() can no longer be implicitly converted to the type“lvalue reference toB”: since the declarationB&t = A(); is not well formed (it invokes a deleted function),there is no implicit conversion. So we unambiguously convert the thirdoperand to anA prvalue.

These should presumably either both be valid or both invalid.EDG and gcc call both ambiguous.

Notes from the June, 2014 meeting:

The wording should be changed to handle the convertibilitytest more like overload resolution: the conversion "exists" ifthe conversion function is declared, but is ill-formed if itwould actually be used.

Proposed resolution (October, 2015):

  1. Add the following as a new paragraph following7.6.16 [expr.cond] paragraph 2:

  2. Otherwise, if the second and third operand are glvaluebit-fields of the same value category and oftypescv1T andcv2T, respectively, the operands areconsidered to be of typecvT for theremainder of this section, wherecv is the unionofcv1 andcv2.
  3. Change 7.6.16 [expr.cond] paragraph 3 as follows:

  4. Otherwise, if the second and third operand have differenttypes and either has (possibly cv-qualified) class type, orif both are glvalues of the same value category and the sametype except for cv-qualification, an attempt is made toconvertform an implicit conversion sequence(12.2.4.2 [over.best.ics]) from each of thoseoperands to the type of the other.[Note:Properties such as access, whether an operand is abit-field, or whether a conversion function is deleted areignored for that determination. —endnote]The process for determining whether anoperand expressionE1 of typeT1 can beconverted to match an operand expressionE2 oftypeT2 is defined as follows:Attemptsare made to form an implicit conversion sequence from anoperand expressionE1 of typeT1 to atarget type related to the typeT2 of the operand expressionE2 asfollows:

    Using this process, it is determined whetheranimplicit conversion sequence can be formed from thesecond operandcan be converted to matchto the target type determined for the thirdoperand, andwhether the third operand can be convertedto match the second operandvice versa. Ifbothcan be convertedsequences can beformed, or onecan be converted but theconversion isformed, but it is the ambiguousconversion sequence, the program is ill-formed. Ifneither can be convertedno conversionsequence can be formed, the operands are leftunchanged and further checking is performed as describedbelow.If exactly one conversion ispossible,Otherwise, if exactly one conversionsequence can be formed, that conversion is applied tothe chosen operand and the converted operand is used inplace of the original operand for the remainder of thissection.[Note: The conversion might beill-formed even if an implicit conversion sequence couldbe formed. —end note]

This resolution also resolvesissue 1932.




[8]ページ先頭

©2009-2025 Movatter.jp