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