From: Richard Smith Date: Thu, 20 Nov 2014 01:24:12 +0000 (+0000) Subject: PR21531: fix crash on invalid with unexpanded pack in case value. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=537df3dd374d45be68d48f88704b44c56ac5c465;p=clang PR21531: fix crash on invalid with unexpanded pack in case value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222400 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 3c4085afe1..0d2d6032dd 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -388,14 +388,19 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, } } - LHSVal = ActOnFinishFullExpr(LHSVal, LHSVal->getExprLoc(), false, - getLangOpts().CPlusPlus11).get(); - if (RHSVal) - RHSVal = ActOnFinishFullExpr(RHSVal, RHSVal->getExprLoc(), false, - getLangOpts().CPlusPlus11).get(); - - CaseStmt *CS = new (Context) CaseStmt(LHSVal, RHSVal, CaseLoc, DotDotDotLoc, - ColonLoc); + auto LHS = ActOnFinishFullExpr(LHSVal, LHSVal->getExprLoc(), false, + getLangOpts().CPlusPlus11); + if (LHS.isInvalid()) + return StmtError(); + + auto RHS = RHSVal ? ActOnFinishFullExpr(RHSVal, RHSVal->getExprLoc(), false, + getLangOpts().CPlusPlus11) + : ExprResult(); + if (RHS.isInvalid()) + return StmtError(); + + CaseStmt *CS = new (Context) + CaseStmt(LHS.get(), RHS.get(), CaseLoc, DotDotDotLoc, ColonLoc); getCurFunction()->SwitchStack.back()->addSwitchCase(CS); return CS; } diff --git a/test/CXX/temp/temp.decls/temp.variadic/p5.cpp b/test/CXX/temp/temp.decls/temp.variadic/p5.cpp index 8a70db6789..4f9368f6b6 100644 --- a/test/CXX/temp/temp.decls/temp.variadic/p5.cpp +++ b/test/CXX/temp/temp.decls/temp.variadic/p5.cpp @@ -354,6 +354,7 @@ void test_unexpanded_exprs(Types ...values) { for (auto t : values) { } // expected-error{{expression contains unexpanded parameter pack 'values'}} switch (values) { } // expected-error{{expression contains unexpanded parameter pack 'values'}} + switch (0) { case 0: case values: ; } // expected-error{{expression contains unexpanded parameter pack 'values'}} do { } while (values); // expected-error{{expression contains unexpanded parameter pack 'values'}}