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
11using namespace clang;
12
13namespace {
14
15// Matches (optional) explicit template parameters.
16class LambdaTemplateParametersVisitor
17 : public ExpectedLocationVisitor<LambdaTemplateParametersVisitor> {
18public:
19 bool shouldVisitImplicitCode() const { return false; }
20
21 bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
22 EXPECT_FALSE(D->isImplicit());
23 Match(Name: D->getName(), Location: D->getBeginLoc());
24 return true;
25 }
26
27 bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
28 EXPECT_FALSE(D->isImplicit());
29 Match(Name: D->getName(), Location: D->getBeginLoc());
30 return true;
31 }
32
33 bool VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
34 EXPECT_FALSE(D->isImplicit());
35 Match(Name: D->getName(), Location: D->getBeginLoc());
36 return true;
37 }
38};
39
40TEST(RecursiveASTVisitor, VisitsLambdaExplicitTemplateParameters) {
41 LambdaTemplateParametersVisitor Visitor;
42 Visitor.ExpectMatch(Match: "T", Line: 2, Column: 15);
43 Visitor.ExpectMatch(Match: "I", Line: 2, Column: 24);
44 Visitor.ExpectMatch(Match: "TT", Line: 2, Column: 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
53

source code of clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp