Quoting from C++ standard draft N4296, Section 5.16 Conditional operator, Paragraph 6.3:
- One or both of the second and third operands have pointer type; pointer conversions (4.10) and
qualification conversions (4.4) are performed to bring them to their composite pointer type (Clause 5).
The result is of the composite pointer type.
Section 5 Expressions, Paragraph 13.8 and 13.9:
The composite pointer type of two operands p1 and p2 having types T1 and T2, respectively, where at
least one is a pointer or pointer to member type or std::nullptr_t, is:
- if T1 and T2 are similar types (4.4), the cv-combined type of T1 and T2;
- otherwise, a program that necessitates the determination of a composite pointer type is ill-formed.
Note: I copied 5/13.8 here just to show you that it doesn’t hit. What’s actually in effect is 5/13.9, “the program is ill-formed”.
And Section 4.10 Pointer conversions, Paragraph 3:
A prvalue of type “pointer to cv D”, where D is a class type, can be converted to a prvalue of type “pointer
to cv B”, where B is a base class (Clause 10) of D. If B is an inaccessible (Clause 11) or ambiguous (10.2)
base class of D, a program that necessitates this conversion is ill-formed. The result of the conversion is a
pointer to the base class subobject of the derived class object. The null pointer value is converted to the
null pointer value of the destination type.
So, it doesn’t matter (at all) that both Foo and Bar are derived from one same base class. It only matters that a pointer to Foo and a pointer to Bar are not convertible to each other (no inheritance relationship).