David Zarzycki | d488daa | 2018-04-19 18:19:02 +0000 | [diff] [blame] | 1 | //===- unittest/Tooling/RecursiveASTVisitorTests/Class.cpp ----------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
David Zarzycki | d488daa | 2018-04-19 18:19:02 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "TestVisitor.h" |
| 10 | |
| 11 | using namespace clang; |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | // Checks for lambda classes that are not marked as implicitly-generated. |
| 16 | // (There should be none.) |
| 17 | class ClassVisitor : public ExpectedLocationVisitor<ClassVisitor> { |
| 18 | public: |
| 19 | ClassVisitor() : SawNonImplicitLambdaClass(false) {} |
| 20 | bool VisitCXXRecordDecl(CXXRecordDecl* record) { |
| 21 | if (record->isLambda() && !record->isImplicit()) |
| 22 | SawNonImplicitLambdaClass = true; |
| 23 | return true; |
| 24 | } |
| 25 | |
| 26 | bool sawOnlyImplicitLambdaClasses() const { |
| 27 | return !SawNonImplicitLambdaClass; |
| 28 | } |
| 29 | |
| 30 | private: |
| 31 | bool SawNonImplicitLambdaClass; |
| 32 | }; |
| 33 | |
| 34 | TEST(RecursiveASTVisitor, LambdaClosureTypesAreImplicit) { |
| 35 | ClassVisitor Visitor; |
| 36 | EXPECT_TRUE(Visitor.runOver("auto lambda = []{};", ClassVisitor::Lang_CXX11)); |
| 37 | EXPECT_TRUE(Visitor.sawOnlyImplicitLambdaClasses()); |
| 38 | } |
| 39 | |
| 40 | } // end anonymous namespace |