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