diff options
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 4 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/throw-expressions.cpp | 24 | ||||
-rw-r--r-- | clang/test/SemaCXX/conditional-expr.cpp | 2 |
3 files changed, 28 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 439fc1636f5..087fea206d7 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -4273,8 +4273,8 @@ QualType Sema::CXXCheckConditionalOperands(ExprResult &Cond, ExprResult &LHS, // ... 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 a prvalue. - bool LThrow = isa<CXXThrowExpr>(LHS.get()); - bool RThrow = isa<CXXThrowExpr>(RHS.get()); + bool LThrow = isa<CXXThrowExpr>(LHS.get()->IgnoreParenCasts()); + bool RThrow = isa<CXXThrowExpr>(RHS.get()->IgnoreParenCasts()); if (LThrow && !RThrow) return RTy; if (RThrow && !LThrow) diff --git a/clang/test/CodeGenCXX/throw-expressions.cpp b/clang/test/CodeGenCXX/throw-expressions.cpp index ba8a86881a6..87c481b25fe 100644 --- a/clang/test/CodeGenCXX/throw-expressions.cpp +++ b/clang/test/CodeGenCXX/throw-expressions.cpp @@ -43,3 +43,27 @@ int test5(bool x, bool y, int z) { // // end: // CHECK: ret i32 + +int test6(bool x, bool y, int z) { + return (x ? throw 1 : y) ? z : (throw 2); +} +// CHECK: define i32 @_Z5test6bbi( +// CHECK: br i1 +// +// x.true: +// CHECK: call void @__cxa_throw( +// CHECK-NEXT: unreachable +// +// x.false: +// CHECK: br i1 +// +// y.true: +// CHECK: load i32* +// CHECK: br label +// +// y.false: +// CHECK: call void @__cxa_throw( +// CHECK-NEXT: unreachable +// +// end: +// CHECK: ret i32 diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp index 692aaefc9d5..5abee4a3c4f 100644 --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -81,6 +81,8 @@ void test() i1 ? test() : test(); i1 = i1 ? throw 0 : 0; i1 = i1 ? 0 : throw 0; + i1 = i1 ? (throw 0) : 0; + i1 = i1 ? 0 : (throw 0); i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}} i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}} (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}} |