From b13f5adf4637a3d03f4c084ff8ec53da8515e3b8 Mon Sep 17 00:00:00 2001 From: Ben Langmuir <blangmuir@apple.com> 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236246 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Preprocessor.h | 2 +- test/Parser/objcxx0x-lambda-expressions.mm | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index ad8589e0868..b1cb00ec590 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/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/test/Parser/objcxx0x-lambda-expressions.mm b/test/Parser/objcxx0x-lambda-expressions.mm index 3954a807a5f..c6ed121f8b4 100644 --- a/test/Parser/objcxx0x-lambda-expressions.mm +++ b/test/Parser/objcxx0x-lambda-expressions.mm @@ -41,3 +41,16 @@ class C { }; +struct Func { + template <typename F> + Func(F&&); +}; + +int getInt(); + +void test() { + [val = getInt()]() { }; + Func{ + [val = getInt()]() { } + }; +} -- GitLab