[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
Mon Jul 1 04:49:03 PDT 2019
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"(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63817.207261.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190701/d1045090/attachment-0001.bin>
More information about the cfe-commits
mailing list