]> granicus.if.org Git - clang/commitdiff
[AST] RecursiveASTVisitor should not crash on lambdas with type attributes
authorAlex Lorenz <arphaman@gmail.com>
Wed, 10 May 2017 16:21:00 +0000 (16:21 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 10 May 2017 16:21:00 +0000 (16:21 +0000)
rdar://31960860

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302689 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/RecursiveASTVisitor.h
unittests/Tooling/RecursiveASTVisitorTest.cpp

index 1b5850a05b37452d84569ae715de8a775771f638..cd2a39449825b4d2db838be919d6a2bec5461d3b 100644 (file)
@@ -2326,7 +2326,7 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
   }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
-  FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
+  FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
 
   if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
     // Visit the whole type.
index 7e08f9619c1c60a3f80cd62267ad6acaf3f38af7..269bdbb34ab139537c4d107b34c98ca9da605138 100644 (file)
@@ -52,6 +52,14 @@ TEST(RecursiveASTVisitor, TraverseLambdaBodyCanBeOverridden) {
   EXPECT_TRUE(Visitor.allBodiesHaveBeenTraversed());
 }
 
+TEST(RecursiveASTVisitor, VisitsAttributedLambdaExpr) {
+  LambdaExprVisitor Visitor;
+  Visitor.ExpectMatch("", 1, 12);
+  EXPECT_TRUE(Visitor.runOver(
+      "void f() { [] () __attribute__ (( fastcall )) { return; }(); }",
+      LambdaExprVisitor::Lang_CXX14));
+}
+
 // Matches the (optional) capture-default of a lambda-introducer.
 class LambdaDefaultCaptureVisitor
   : public ExpectedLocationVisitor<LambdaDefaultCaptureVisitor> {