[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / NestedNameSpecifiers.cpp
blobddc663e2b6fd3f479f97ad3499730a0af81c9587
1 //===- unittest/Tooling/RecursiveASTVisitorTests/NestedNameSpecifiers.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 //===----------------------------------------------------------------------===//
9 #include "TestVisitor.h"
11 using namespace clang;
13 namespace {
15 // Check to ensure that nested name specifiers are visited.
16 class NestedNameSpecifiersVisitor : public ExpectedLocationVisitor {
17 public:
18 bool VisitRecordTypeLoc(RecordTypeLoc RTL) override {
19 if (!RTL)
20 return true;
21 Match(RTL.getDecl()->getName(), RTL.getNameLoc());
22 return true;
25 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) override {
26 if (!NNS)
27 return true;
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"(
38 namespace ns {
39 struct Outer {
40 template<typename T, typename U>
41 struct Nested { };
43 template<typename T>
44 static T x;
48 template<>
49 struct ns::Outer::Nested<int, int>;
51 template<>
52 struct ns::Outer::Nested<int, int> { };
54 template<typename T>
55 struct ns::Outer::Nested<int, T> { };
57 template<>
58 int ns::Outer::x<int> = 0;
59 )";
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