[PATCH] D63817: [clangd] No longer getting template instantiations from header files in Main AST.

Johan Vikström via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 07:26:27 PDT 2019


jvikstrom updated this revision to Diff 206664.
jvikstrom added a comment.

Removed comment, getting SM from Decl and removed old check for checking the file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63817/new/

https://reviews.llvm.org/D63817

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp


Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -83,6 +83,23 @@
   EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
 }
 
+TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) {
+  TestTU TU;
+  TU.HeaderCode = R"cpp(
+    template<class T>
+    struct H {
+      H() {}
+    };
+  )cpp";
+  TU.Code = R"cpp(
+    int main() {
+      H<int> h;
+    }
+  )cpp";
+  auto AST = TU.build();
+  EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
+}
+
 TEST(ClangdUnitTest, TokensAfterPreamble) {
   TestTU TU;
   TU.AdditionalFiles["foo.h"] = R"(
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <memory>
+#include <iostream>
 
 namespace clang {
 namespace clangd {
@@ -67,7 +68,7 @@
 
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
     for (Decl *D : DG) {
-      if (D->isFromASTFile())
+      if (!D->getASTContext().getSourceManager().isInMainFile(D->getLocation()))
         continue;
 
       // ObjCMethodDecl are not actually top-level decls.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63817.206664.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190626/1ae95a3a/attachment.bin>


More information about the cfe-commits mailing list