1 //===- unittest/Tooling/RecursiveASTVisitorTests/NestedNameSpecifiers.cpp -===//
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
7 //===----------------------------------------------------------------------===//
9 #include "TestVisitor.h"
11 using namespace clang
;
15 // Check to ensure that nested name specifiers are visited.
16 class NestedNameSpecifiersVisitor
: public ExpectedLocationVisitor
{
18 bool VisitRecordTypeLoc(RecordTypeLoc RTL
) override
{
21 Match(RTL
.getDecl()->getName(), RTL
.getNameLoc());
25 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS
) override
{
28 if (const NamespaceDecl
*ND
=
29 NNS
.getNestedNameSpecifier()->getAsNamespace())
30 Match(ND
->getName(), NNS
.getLocalBeginLoc());
31 return ExpectedLocationVisitor::TraverseNestedNameSpecifierLoc(NNS
);
35 TEST(RecursiveASTVisitor
,
36 NestedNameSpecifiersForTemplateSpecializationsAreVisited
) {
37 StringRef Source
= R
"(
40 template<typename T, typename U>
49 struct ns::Outer::Nested<int, int>;
52 struct ns::Outer::Nested<int, int> { };
55 struct ns::Outer::Nested<int, T> { };
58 int ns::Outer::x<int> = 0;
60 NestedNameSpecifiersVisitor Visitor
;
61 Visitor
.ExpectMatch("ns", 13, 8);
62 Visitor
.ExpectMatch("ns", 16, 8);
63 Visitor
.ExpectMatch("ns", 19, 8);
64 Visitor
.ExpectMatch("ns", 22, 5);
65 Visitor
.ExpectMatch("Outer", 13, 12);
66 Visitor
.ExpectMatch("Outer", 16, 12);
67 Visitor
.ExpectMatch("Outer", 19, 12);
68 Visitor
.ExpectMatch("Outer", 22, 9);
69 EXPECT_TRUE(Visitor
.runOver(Source
, NestedNameSpecifiersVisitor::Lang_CXX14
));
72 } // end anonymous namespace