In C++, if throw is an expression, what is its type?

后端 未结 4 555
耶瑟儿~
耶瑟儿~ 2020-12-07 13:29

I picked this up in one of my brief forays to reddit:

http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/

Basically, the a

4条回答
  •  無奈伤痛
    2020-12-07 14:30

    From [expr.cond.2] (conditional operator ?:):

    If either the second or the third operand has type (possibly cv-qualified) void, then the lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversions are performed on the second and third operands, and one of the following shall hold:

    — The second or the third operand (but not both) is a throw-expression; the result is of the type of the other and is an rvalue.

    — Both the second and the third operands have type void; the result is of type void and is an rvalue. [ Note: this includes the case where both operands are throw-expressions. — end note ]

    So, with //1 you were in the first case, with //2, you were violating "one of the following shall hold", since none of them do, in that case.

提交回复
热议问题