diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -10368,10 +10368,16 @@ MaxWidth, InConstantContext); // Otherwise, conservatively merge. - IntRange L = - GetExprRange(C, CO->getTrueExpr(), MaxWidth, InConstantContext); - IntRange R = - GetExprRange(C, CO->getFalseExpr(), MaxWidth, InConstantContext); + // GetExprRange requires an integer expression, but a throw expression + // results in a void type. + Expr *E = CO->getTrueExpr(); + IntRange L = E->getType()->isVoidType() + ? IntRange{0, true} + : GetExprRange(C, E, MaxWidth, InConstantContext); + E = CO->getFalseExpr(); + IntRange R = E->getType()->isVoidType() + ? IntRange{0, true} + : GetExprRange(C, E, MaxWidth, InConstantContext); return IntRange::join(L, R); } diff --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp --- a/clang/test/SemaCXX/conditional-expr.cpp +++ b/clang/test/SemaCXX/conditional-expr.cpp @@ -409,3 +409,20 @@ D d = b ? D{B()} : D{C()}; } } + +namespace PR46484 { +// expected-error@+4{{expected ':'}} +// expected-note@+3{{to match this '?'}} +// expected-warning@+2{{variable 'b' is uninitialized}} +// expected-error@+1 2 {{expected ';' after top level declarator}} +int a long b = a = b ? throw 0 1 + +void g() { + extern int a; + extern long b; + long c = a = b ? throw 0 : 1; + long d = a = b ? 1 : throw 0; + // expected-error@+1 {{assigning to 'int' from incompatible type 'void'}} + long e = a = b ? throw 0 : throw 1; +} +} // namespace PR46484