This revision was automatically updated to reflect the committed changes. Closed by commit rL364747: [clangd] No longer getting template instantiations from header files in Main… (authored by jvikstrom, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D63817?vs=206685&id=207261#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63817/new/ https://reviews.llvm.org/D63817 Files: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp @@ -67,7 +67,8 @@ bool HandleTopLevelDecl(DeclGroupRef DG) override { for (Decl *D : DG) { - if (D->isFromASTFile()) + auto &SM = D->getASTContext().getSourceManager(); + if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation()))) continue; // ObjCMethodDecl are not actually top-level decls. Index: clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp +++ clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp @@ -83,6 +83,26 @@ EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main"))); } +TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) { + TestTU TU; + TU.HeaderCode = R"cpp( + #define LL void foo(){} + template<class T> + struct H { + H() {} + LL + }; + )cpp"; + TU.Code = R"cpp( + int main() { + H<int> h; + h.foo(); + } + )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/trunk/clangd/ClangdUnit.cpp =================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp @@ -67,7 +67,8 @@ bool HandleTopLevelDecl(DeclGroupRef DG) override { for (Decl *D : DG) { - if (D->isFromASTFile()) + auto &SM = D->getASTContext().getSourceManager(); + if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation()))) continue; // ObjCMethodDecl are not actually top-level decls. Index: clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp +++ clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp @@ -83,6 +83,26 @@ EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main"))); } +TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) { + TestTU TU; + TU.HeaderCode = R"cpp( + #define LL void foo(){} + template<class T> + struct H { + H() {} + LL + }; + )cpp"; + TU.Code = R"cpp( + int main() { + H<int> h; + h.foo(); + } + )cpp"; + auto AST = TU.build(); + EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main"))); +} + TEST(ClangdUnitTest, TokensAfterPreamble) { TestTU TU; TU.AdditionalFiles["foo.h"] = R"(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits