Fix the end location of init-capture annotations in ObjC++
authorBen Langmuir <blangmuir@apple.com>
Thu, 30 Apr 2015 18:40:23 +0000 (18:40 +0000)
committerBen Langmuir <blangmuir@apple.com>
Thu, 30 Apr 2015 18:40:23 +0000 (18:40 +0000)
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
clang/test/Parser/objcxx0x-lambda-expressions.mm

index ad8589e..b1cb00e 100644 (file)
@@ -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.
index 3954a80..c6ed121 100644 (file)
@@ -41,3 +41,16 @@ class C {
 
 };
 
+struct Func {
+  template <typename F>
+  Func(F&&);
+};
+
+int getInt();
+
+void test() {
+  [val = getInt()]() { };
+  Func{
+    [val = getInt()]() { }
+  };
+}