David Zarzycki | d488daa | 2018-04-19 18:19:02 +0000 | [diff] [blame^] | 1 | //===- unittest/Tooling/RecursiveASTVisitorTests/Class.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 | // Checks for lambda classes that are not marked as implicitly-generated. |
| 17 | // (There should be none.) |
| 18 | class ClassVisitor : public ExpectedLocationVisitor<ClassVisitor> { |
| 19 | public: |
| 20 | ClassVisitor() : SawNonImplicitLambdaClass(false) {} |
| 21 | bool VisitCXXRecordDecl(CXXRecordDecl* record) { |
| 22 | if (record->isLambda() && !record->isImplicit()) |
| 23 | SawNonImplicitLambdaClass = true; |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | bool sawOnlyImplicitLambdaClasses() const { |
| 28 | return !SawNonImplicitLambdaClass; |
| 29 | } |
| 30 | |
| 31 | private: |
| 32 | bool SawNonImplicitLambdaClass; |
| 33 | }; |
| 34 | |
| 35 | TEST(RecursiveASTVisitor, LambdaClosureTypesAreImplicit) { |
| 36 | ClassVisitor Visitor; |
| 37 | EXPECT_TRUE(Visitor.runOver("auto lambda = []{};", ClassVisitor::Lang_CXX11)); |
| 38 | EXPECT_TRUE(Visitor.sawOnlyImplicitLambdaClasses()); |
| 39 | } |
| 40 | |
| 41 | } // end anonymous namespace |