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