r225505 - Parse: Don't crash when trailing return type is missing
David Majnemer
david.majnemer at gmail.com
Thu Jan 8 21:10:55 PST 2015
Author: majnemer
Date: Thu Jan 8 23:10:55 2015
New Revision: 225505
URL: http://llvm.org/viewvc/llvm-project?rev=225505&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=225505&r1=225504&r2=225505&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu Jan 8 23:10:55 2015
@@ -1052,6 +1052,7 @@ ExprResult Parser::ParseLambdaExpression
TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
Actions.PushLambdaScope();
+ TypeResult TrailingReturnType;
if (Tok.is(tok::l_paren)) {
ParseScope PrototypeScope(this,
Scope::FunctionPrototypeScope |
@@ -1112,7 +1113,6 @@ ExprResult Parser::ParseLambdaExpression
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::ParseLambdaExpression
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::ParseLambdaExpression
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();
}
Modified: cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp?rev=225505&r1=225504&r2=225505&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp (original)
+++ cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp Thu Jan 8 23:10:55 2015
@@ -91,3 +91,10 @@ class C {
__attribute__((noreturn)) { while(1); }; // expected-error {{expected body of lambda expression}}
}
};
+
+template <typename>
+void PR22122() {
+ [](int) -> {}; // expected-error {{expected a type}}
+}
+
+template void PR22122<int>();
More information about the cfe-commits
mailing list