Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 1 | //===- unittest/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.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 | // Matches (optional) explicit template parameters. |
| 17 | class LambdaTemplateParametersVisitor |
| 18 | : public ExpectedLocationVisitor<LambdaTemplateParametersVisitor> { |
| 19 | public: |
| 20 | bool shouldVisitImplicitCode() const { return false; } |
| 21 | |
| 22 | bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 23 | EXPECT_FALSE(D->isImplicit()); |
| 24 | Match(D->getName(), D->getBeginLoc()); |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 29 | EXPECT_FALSE(D->isImplicit()); |
| 30 | Match(D->getName(), D->getBeginLoc()); |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | bool VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 35 | EXPECT_FALSE(D->isImplicit()); |
| 36 | Match(D->getName(), D->getBeginLoc()); |
| 37 | return true; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | TEST(RecursiveASTVisitor, VisitsLambdaExplicitTemplateParameters) { |
| 42 | LambdaTemplateParametersVisitor Visitor; |
| 43 | Visitor.ExpectMatch("T", 2, 15); |
| 44 | Visitor.ExpectMatch("I", 2, 24); |
| 45 | Visitor.ExpectMatch("TT", 2, 31); |
| 46 | EXPECT_TRUE(Visitor.runOver( |
| 47 | "void f() { \n" |
| 48 | " auto l = []<class T, int I, template<class> class TT>(auto p) { }; \n" |
| 49 | "}", |
| 50 | LambdaTemplateParametersVisitor::Lang_CXX2a)); |
| 51 | } |
| 52 | |
| 53 | } // end anonymous namespace |