1//===- TemplateArgumentLocTraverser.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
15class TemplateArgumentLocTraverser
16 : public ExpectedLocationVisitor<TemplateArgumentLocTraverser> {
17public:
18 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
19 std::string ArgStr;
20 llvm::raw_string_ostream Stream(ArgStr);
21 const TemplateArgument &Arg = ArgLoc.getArgument();
22
23 Arg.print(Policy: Context->getPrintingPolicy(), Out&: Stream, /*IncludeType*/ true);
24 Match(Name: Stream.str(), Location: ArgLoc.getLocation());
25 return ExpectedLocationVisitor<TemplateArgumentLocTraverser>::
26 TraverseTemplateArgumentLoc(ArgLoc);
27 }
28};
29
30TEST(RecursiveASTVisitor, VisitsClassTemplateTemplateParmDefaultArgument) {
31 TemplateArgumentLocTraverser Visitor;
32 Visitor.ExpectMatch(Match: "X", Line: 2, Column: 40);
33 EXPECT_TRUE(Visitor.runOver(
34 "template<typename T> class X;\n"
35 "template<template <typename> class T = X> class Y;\n"
36 "template<template <typename> class T> class Y {};\n"));
37}
38
39} // end anonymous namespace
40

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