David Zarzycki | d488daa | 2018-04-19 18:19:02 +0000 | [diff] [blame^] | 1 | //===- unittest/Tooling/RecursiveASTVisitorTests/LambdaDefaultCapture.cpp -===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "TestVisitor.h" |
| 11 | |
| 12 | using namespace clang; |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | // Matches the (optional) capture-default of a lambda-introducer. |
| 17 | class LambdaDefaultCaptureVisitor |
| 18 | : public ExpectedLocationVisitor<LambdaDefaultCaptureVisitor> { |
| 19 | public: |
| 20 | bool VisitLambdaExpr(LambdaExpr *Lambda) { |
| 21 | if (Lambda->getCaptureDefault() != LCD_None) { |
| 22 | Match("", Lambda->getCaptureDefaultLoc()); |
| 23 | } |
| 24 | return true; |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | TEST(RecursiveASTVisitor, HasCaptureDefaultLoc) { |
| 29 | LambdaDefaultCaptureVisitor Visitor; |
| 30 | Visitor.ExpectMatch("", 1, 20); |
| 31 | EXPECT_TRUE(Visitor.runOver("void f() { int a; [=]{a;}; }", |
| 32 | LambdaDefaultCaptureVisitor::Lang_CXX11)); |
| 33 | } |
| 34 | |
| 35 | } // end anonymous namespace |