From: Bruno Cardoso Lopes Date: Tue, 31 May 2016 18:46:31 +0000 (+0000) Subject: [Parser] Fix look ahead after EOF while parsing objc message and lambdas X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d98619f8ed131a9363f39ae0eb07a431e4d6c42;p=clang [Parser] Fix look ahead after EOF while parsing objc message and lambdas If a closing ')' isn't found for a macro instantiation inside a '[', the next token is EOF, this leads to crashes if we try to look ahead of that. This could be triggered whenever trying to parse lambdas or objs message expressions. Differential Revision: http://reviews.llvm.org/D20451 rdar://problem/25662647 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271314 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index b569e7aeba..b0740970d8 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -739,8 +739,11 @@ ExprResult Parser::TryParseLambdaExpression() { && Tok.is(tok::l_square) && "Not at the start of a possible lambda expression."); - const Token Next = NextToken(), After = GetLookAheadToken(2); + const Token Next = NextToken(); + if (Next.is(tok::eof)) // Nothing else to lookup here... + return ExprEmpty(); + const Token After = GetLookAheadToken(2); // If lookahead indicates this is a lambda... if (Next.is(tok::r_square) || // [] Next.is(tok::equal) || // [= diff --git a/test/Parser/objcxx11-messaging-and-lambda.mm b/test/Parser/objcxx11-messaging-and-lambda.mm new file mode 100644 index 0000000000..002f3e9c71 --- /dev/null +++ b/test/Parser/objcxx11-messaging-and-lambda.mm @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +#define OBJCLASS(name) // expected-note {{macro 'OBJCLASS' defined here}} + +class NSMutableData; + +NSMutableData *test() { // expected-note {{to match this '{'}} + NSMutableData *data = [[[OBJCLASS(NSMutableDataOBJCLASS( alloc] init] autorelease]; // expected-error {{unterminated function-like macro invocation}} \ + // expected-error {{expected ';' at end of declaration}} + return data; +} // expected-error {{expected expression}} expected-error {{expected '}'}}