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
17 : public ExpectedLocationVisitor
<NestedNameSpecifiersVisitor
> {
19 bool VisitRecordTypeLoc(RecordTypeLoc RTL
) {
22 Match(RTL
.getDecl()->getName(), RTL
.getNameLoc());
26 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS
) {
29 if (const NamespaceDecl
*ND
=
30 NNS
.getNestedNameSpecifier()->getAsNamespace())
31 Match(ND
->getName(), NNS
.getLocalBeginLoc());
32 return ExpectedLocationVisitor::TraverseNestedNameSpecifierLoc(NNS
);
36 TEST(RecursiveASTVisitor
,
37 NestedNameSpecifiersForTemplateSpecializationsAreVisited
) {
38 StringRef Source
= R
"(
41 template<typename T, typename U>
50 struct ns::Outer::Nested<int, int>;
53 struct ns::Outer::Nested<int, int> { };
56 struct ns::Outer::Nested<int, T> { };
59 int ns::Outer::x<int> = 0;
61 NestedNameSpecifiersVisitor Visitor
;
62 Visitor
.ExpectMatch("ns", 13, 8);
63 Visitor
.ExpectMatch("ns", 16, 8);
64 Visitor
.ExpectMatch("ns", 19, 8);
65 Visitor
.ExpectMatch("ns", 22, 5);
66 Visitor
.ExpectMatch("Outer", 13, 12);
67 Visitor
.ExpectMatch("Outer", 16, 12);
68 Visitor
.ExpectMatch("Outer", 19, 12);
69 Visitor
.ExpectMatch("Outer", 22, 9);
70 EXPECT_TRUE(Visitor
.runOver(Source
, NestedNameSpecifiersVisitor::Lang_CXX14
));
73 } // end anonymous namespace