nridge created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov.
Herald added a project: clang.

This is not meant to be committed, it's meant to demonstrate an
issue with using RecursiveASTVisitor with TestTU on code that contains a
top-level variable template.

The variable template declaration is never visited, for reasons I don't
fully understand.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60954

Files:
  clang-tools-extra/unittests/clangd/TestTU.cpp


Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===================================================================
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -141,5 +141,24 @@
   });
 }
 
+class TestVisitor : public RecursiveASTVisitor<TestVisitor> {
+public:
+  bool VisitVarTemplateDecl(VarTemplateDecl *VTD) {
+    seenVarTemplateDecl = true;
+    return true;
+  }
+
+  bool seenVarTemplateDecl = false;
+};
+
+TEST(TestTU, VariableTemplate) {
+  TestTU TU = TestTU::withCode("template <typename T> int x;");
+  auto AST = TU.build();
+  EXPECT_TRUE(AST.getDiagnostics().empty());
+  TestVisitor Visitor;
+  Visitor.TraverseAST(AST.getASTContext());
+  EXPECT_TRUE(Visitor.seenVarTemplateDecl);
+}
+
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===================================================================
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -141,5 +141,24 @@
   });
 }
 
+class TestVisitor : public RecursiveASTVisitor<TestVisitor> {
+public:
+  bool VisitVarTemplateDecl(VarTemplateDecl *VTD) {
+    seenVarTemplateDecl = true;
+    return true;
+  }
+
+  bool seenVarTemplateDecl = false;
+};
+
+TEST(TestTU, VariableTemplate) {
+  TestTU TU = TestTU::withCode("template <typename T> int x;");
+  auto AST = TU.build();
+  EXPECT_TRUE(AST.getDiagnostics().empty());
+  TestVisitor Visitor;
+  Visitor.TraverseAST(AST.getASTContext());
+  EXPECT_TRUE(Visitor.seenVarTemplateDecl);
+}
+
 } // namespace clangd
 } // namespace clang
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D60954: [clangd] Test... Nathan Ridge via Phabricator via cfe-commits

Reply via email to