Reputation: 7369
Because the sections of [expr.cond] are too long,I only cite the section 6 and part of section 7 here,other sections will be given in the link [expr.cond]
6.Otherwise, the result is a prvalue. If the second and third operands do not have the same type, and either has (possibly cv-qualified) class type, overload resolution is used to determine the conversions (if any) to be applied to the operands ([over.match.oper], [over.built]). If the overload resolution fails, the program is ill-formed. Otherwise, the conversions thus determined are applied, and the converted operands are used in place of the original operands for the remainder of this section.
7.Lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversions are performed on the second and third operands. After those conversions, one of the following shall hold:
7.1 The second and third operands have the same type; the result is of that type and the result object is initialized using the selected operand.
7.2 The second and third operands have arithmetic or enumeration type; the usual arithmetic conversions are performed to bring them to a common type, and the result is of that type.
Let us consider the following situation:
#include <iostream>
int main(){
bool b = true;
int a = 0;
auto r = b?'c':a; //#1
}
We know the expression #1
does not conform to [expr.cond]/2,[expr.cond]/3,[expr.cond]/4,[expr.cond]/5 and we know it's the case of [expr.cond]/6,However only the conditon of If the second and third operands do not have the same type, and either has (possibly cv-qualified) class type,and overload resolution are successful is satisfied,then the section 7 would be performed on the operand,as I read the section 6.Obviously,neither 'c'
nor 'a'
are class type.So,I wonder does the section 7 continue to perform on these operand,especially,the section 7.2.If I misunderstand,How the standard make section 7 to performe for case #1
?
My understanding for sentence 6 as if it's:
if("the second and third operands do not have the same type, and either has (possibly cv-qualified) class type" == true){
if("the overload resolution fails"==true){
"the program is ill-formed"
}else{
"the converted operands are used in place of the original operands for the
remainder of this section" //that means sentence 7 will be performed
}
}
Upvotes: 1
Views: 100
Reputation: 40063
/6 isn’t responsible for “calling” /7; it merely, sometimes, filters its inputs by applying certain conversions to the operands (as well as rendering the expression ill-formed in certain cases). We wouldn’t need “in place of the original operands for the remainder of this section” if we weren’t going to proceed to /7 otherwise.
Upvotes: 2