Class.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===- unittest/Tooling/RecursiveASTVisitorTests/Class.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. // Checks for lambda classes that are not marked as implicitly-generated.
  12. // (There should be none.)
  13. class ClassVisitor : public ExpectedLocationVisitor<ClassVisitor> {
  14. public:
  15. ClassVisitor() : SawNonImplicitLambdaClass(false) {}
  16. bool VisitCXXRecordDecl(CXXRecordDecl* record) {
  17. if (record->isLambda() && !record->isImplicit())
  18. SawNonImplicitLambdaClass = true;
  19. return true;
  20. }
  21. bool sawOnlyImplicitLambdaClasses() const {
  22. return !SawNonImplicitLambdaClass;
  23. }
  24. private:
  25. bool SawNonImplicitLambdaClass;
  26. };
  27. TEST(RecursiveASTVisitor, LambdaClosureTypesAreImplicit) {
  28. ClassVisitor Visitor;
  29. EXPECT_TRUE(Visitor.runOver("auto lambda = []{};", ClassVisitor::Lang_CXX11));
  30. EXPECT_TRUE(Visitor.sawOnlyImplicitLambdaClasses());
  31. }
  32. } // end anonymous namespace