[PATCH] D78848: [clangd] Disable delayed template parsing in the main file
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 18:26:06 PDT 2020
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
This is on by default in windows and breaks most features in template bodies.
We'd already disabled it in code completion, now disable it for building ASTs.
Potential regressions:
- we may give spurious errors where files with templates relying on delayed parsing are directly opened
- we may misparse such template bodies that are instantiated (and therefore *were* previously parsed)
Still *probably* a win overall. Avoiding the regressions entirely would be
substantial work and we don't have plans for it now.
Fixes https://github.com/clangd/clangd/issues/302 (again)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78848
Files:
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -175,6 +175,17 @@
AllOf(DeclNamed("foo"), WithTemplateArgs("<bool>"))}));
}
+TEST(ParsedASTTest, IgnoresDelayedTemplateParsing) {
+ auto TU = TestTU::withCode(R"cpp(
+ template <typename T> void xxx() {
+ int yyy = 0;
+ }
+ )cpp");
+ TU.ExtraArgs.push_back("-fdelayed-template-parsing");
+ auto AST = TU.build();
+ EXPECT_EQ(Decl::Var, findUnqualifiedDecl(AST, "yyy").getKind());
+}
+
TEST(ParsedASTTest, TokensAfterPreamble) {
TestTU TU;
TU.AdditionalFiles["foo.h"] = R"(
Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -256,6 +256,9 @@
// Recovery expression currently only works for C++.
if (CI->getLangOpts()->CPlusPlus)
CI->getLangOpts()->RecoveryAST = Opts.BuildRecoveryAST;
+ // This is on-by-default in windows to allow parsing SDK headers, but it
+ // breaks many features. Disable it for the main-file (not preamble).
+ CI->getLangOpts()->DelayedTemplateParsing = false;
StoreDiags ASTDiags;
std::string Content = std::string(Buffer->getBuffer());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78848.260046.patch
Type: text/x-patch
Size: 1434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200425/d93f08f5/attachment-0001.bin>
More information about the cfe-commits
mailing list