From c861f4174dcf5132a149f83193cfbfd851f18bab Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 30 Apr 2015 18:40:23 +0000 Subject: [PATCH] Fix the end location of init-capture annotations in ObjC++ And thereby stop asserting. In ObjC++ modes, we tentatively parse the lambda introducer twice: once to disambiguate designators, which we also do in C++, and a second time to disambiguate objc message expressions. During the second tentative parse, the last cached token will be the annotation token we built in the first parse. So use getLastLoc() to get the correct end location for the rebuilt annotation. llvm-svn: 236246 --- clang/include/clang/Lex/Preprocessor.h | 2 +- clang/test/Parser/objcxx0x-lambda-expressions.mm | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index ad8589e08689..b1cb00ec5902 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1179,7 +1179,7 @@ public: /// location of an annotation token. SourceLocation getLastCachedTokenLocation() const { assert(CachedLexPos != 0); - return CachedTokens[CachedLexPos-1].getLocation(); + return CachedTokens[CachedLexPos-1].getLastLoc(); } /// \brief Replace the last token with an annotation token. diff --git a/clang/test/Parser/objcxx0x-lambda-expressions.mm b/clang/test/Parser/objcxx0x-lambda-expressions.mm index 3954a807a5fb..c6ed121f8b40 100644 --- a/clang/test/Parser/objcxx0x-lambda-expressions.mm +++ b/clang/test/Parser/objcxx0x-lambda-expressions.mm @@ -41,3 +41,16 @@ class C { }; +struct Func { + template + Func(F&&); +}; + +int getInt(); + +void test() { + [val = getInt()]() { }; + Func{ + [val = getInt()]() { } + }; +}