The type of C++ conditional (ternary) operator E1 ? E2 : E3 in case of distinct types E2 and E3 is selected as one of them if the other operand can be uniquely converted to that type. The set of rules is actually more complex and summarized in https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator
In the following simplified program, the operands of the conditional operator are rvalues of types A and B:
class A;
struct B {
B() {}
B(const A &) {}
};
class A : B {};
int main() {
void( true ? B{} : A{} );
}
Since A is derived privately from B, no cast to parent is possible, but A can be uniquely converted to B using the constructor B::B(const A &). And no cast from B to A is available. So I would expect that the type of the ternary operator be B with the last argument converted in that type. And indeed, Clang accepts the program.
But GCC prints an error here:
error: 'B' is an inaccessible base of 'A'
Demo: https://gcc.godbolt.org/z/n56vf4qzY
Which of the compilers is right here?