LambdaDefaultCapture.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. //===- unittest/Tooling/RecursiveASTVisitorTests/LambdaDefaultCapture.cpp -===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "TestVisitor.h"
  9. using namespace clang;
  10. namespace {
  11. // Matches the (optional) capture-default of a lambda-introducer.
  12. class LambdaDefaultCaptureVisitor
  13. : public ExpectedLocationVisitor<LambdaDefaultCaptureVisitor> {
  14. public:
  15. bool VisitLambdaExpr(LambdaExpr *Lambda) {
  16. if (Lambda->getCaptureDefault() != LCD_None) {
  17. Match("", Lambda->getCaptureDefaultLoc());
  18. }
  19. return true;
  20. }
  21. };
  22. TEST(RecursiveASTVisitor, HasCaptureDefaultLoc) {
  23. LambdaDefaultCaptureVisitor Visitor;
  24. Visitor.ExpectMatch("", 1, 20);
  25. EXPECT_TRUE(Visitor.runOver("void f() { int a; [=]{a;}; }",
  26. LambdaDefaultCaptureVisitor::Lang_CXX11));
  27. }
  28. } // end anonymous namespace