r236246 - Fix the end location of init-capture annotations in ObjC++

Ben Langmuir blangmuir at apple.com
Thu Apr 30 11:40:23 PDT 2015


Author: benlangmuir
Date: Thu Apr 30 13:40:23 2015
New Revision: 236246

URL: http://llvm.org/viewvc/llvm-project?rev=236246&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/test/Parser/objcxx0x-lambda-expressions.mm

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236246&r1=236245&r2=236246&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Apr 30 13:40:23 2015
@@ -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.

Modified: cfe/trunk/test/Parser/objcxx0x-lambda-expressions.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objcxx0x-lambda-expressions.mm?rev=236246&r1=236245&r2=236246&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objcxx0x-lambda-expressions.mm (original)
+++ cfe/trunk/test/Parser/objcxx0x-lambda-expressions.mm Thu Apr 30 13:40:23 2015
@@ -41,3 +41,16 @@ class C {
 
 };
 
+struct Func {
+  template <typename F>
+  Func(F&&);
+};
+
+int getInt();
+
+void test() {
+  [val = getInt()]() { };
+  Func{
+    [val = getInt()]() { }
+  };
+}





More information about the cfe-commits mailing list