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 | |
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 { |
18 | public: |
19 | ClassVisitor() : SawNonImplicitLambdaClass(false) {} |
20 | |
21 | bool VisitCXXRecordDecl(CXXRecordDecl *record) override { |
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 |
42 |