From: David Majnemer Date: Fri, 9 Jan 2015 05:10:55 +0000 (+0000) Subject: Parse: Don't crash when trailing return type is missing X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47c0b41f008e1f8403392ae4781e88c00b366be4;p=clang Parse: Don't crash when trailing return type is missing Sema::CheckParmsForFunctionDef can't cope with a null TypeSourceInfo. Don't let the AST contain the malformed lambda. This fixes PR22122. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225505 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index f101d9f127..355503caa9 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -1052,6 +1052,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); Actions.PushLambdaScope(); + TypeResult TrailingReturnType; if (Tok.is(tok::l_paren)) { ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | @@ -1112,7 +1113,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( SourceLocation FunLocalRangeEnd = DeclEndLoc; // Parse trailing-return-type[opt]. - TypeResult TrailingReturnType; if (Tok.is(tok::arrow)) { FunLocalRangeEnd = Tok.getLocation(); SourceRange Range; @@ -1182,12 +1182,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( MaybeParseCXX11Attributes(Attr, &DeclEndLoc); // Parse the return type, if there is one. - TypeResult TrailingReturnType; if (Tok.is(tok::arrow)) { SourceRange Range; TrailingReturnType = ParseTrailingReturnType(Range); if (Range.getEnd().isValid()) - DeclEndLoc = Range.getEnd(); + DeclEndLoc = Range.getEnd(); } SourceLocation NoLoc; @@ -1235,9 +1234,9 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( StmtResult Stmt(ParseCompoundStatementBody()); BodyScope.Exit(); - if (!Stmt.isInvalid()) + if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid()) return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope()); - + Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); return ExprError(); } diff --git a/test/Parser/cxx0x-lambda-expressions.cpp b/test/Parser/cxx0x-lambda-expressions.cpp index 8cfe7f3b02..4bcc60c73c 100644 --- a/test/Parser/cxx0x-lambda-expressions.cpp +++ b/test/Parser/cxx0x-lambda-expressions.cpp @@ -91,3 +91,10 @@ class C { __attribute__((noreturn)) { while(1); }; // expected-error {{expected body of lambda expression}} } }; + +template +void PR22122() { + [](int) -> {}; // expected-error {{expected a type}} +} + +template void PR22122();