Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
1 of 6
Qaz
  • 62.3k
  • 14
  • 149
  • 210

I don't have N3936 handy, but N3797 §5.12 [expr.cond]/3 contains this (emphasis mine):

Otherwise, if the second and third operand have different types and either has (possibly cv-qualified) class type, or if both are glvalues of the same value category and the same type except for cv-qualification, an attempt is made to convert each of those operands to the type of the other. The process for determining whether an operand expression E1 of type T1 can be converted to match an operand expression E2 of type T2 is defined as follows:

  • If E2 is an lvalue: [removed]
  • If E2 is an xvalue: [removed]
  • If E2 is a prvalue or if neither of the conversions above can be done and at least one of the operands has (possibly cv-qualified) class type:
  • if E1 and E2 have class type, and the underlying class types are the same or one is a base class of the other:
    E1 can be converted to match E2 if the class of T2 is the same type as, or a base class of, the class of T1, and the cv-qualification of T2 is the same cv-qualification as, or a greater cv-qualification than, the cv-qualification of T1. If the conversion is applied, E1 is changed to a prvalue of type T2 by copy-initializing a temporary of type T2 from E1 and using that temporary as the converted operand.

Using this process, it is determined whether the second operand can be converted to match the third operand, and whether the third operand can be converted to match the second operand. If both can be converted, or one can be converted but the conversion is ambiguous, the program is ill-formed. If neither can be converted, the operands are left unchanged and further checking is performed as described below. If exactly one conversion is possible, that conversion is applied to the chosen operand and the converted operand is used in place of the original operand for the remainder of this section.

Judging by this, the instance of Derived should be used to copy-initialize the final operand of type Base. Since you have an accessible copy-constructor, this should be fine. It looks like Clang is trying to move it, as implementing the move constructor via = default; causes Clang to successfully compile the program.

Qaz
  • 62.3k
  • 14
  • 149
  • 210