Skip to content

Commit 68dbd1a

Browse files
committed
[clangd] Add include-fixer fixit for no_member_template diagnostic.
Differential Revision: https://reviews.llvm.org/D95365
1 parent e98d5c3 commit 68dbd1a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
100100
case diag::err_undeclared_var_use_suggest:
101101
case diag::err_no_member: // Could be no member in namespace.
102102
case diag::err_no_member_suggest:
103+
case diag::err_no_member_template:
104+
case diag::err_no_member_template_suggest:
103105
if (LastUnresolvedName) {
104106
// Try to fix unresolved name caused by missing declaration.
105107
// E.g.

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,13 @@ void bar() {
879879
880880
::$global[[Global]] glob;
881881
}
882+
using Type = ns::$template[[Foo]]<int>;
882883
)cpp");
883884
auto TU = TestTU::withCode(Test.code());
884885
auto Index = buildIndexWithSymbol(
885886
{SymbolWithHeader{"ns::X", "unittest:///x.h", "\"x.h\""},
886-
SymbolWithHeader{"Global", "unittest:///global.h", "\"global.h\""}});
887+
SymbolWithHeader{"Global", "unittest:///global.h", "\"global.h\""},
888+
SymbolWithHeader{"ns::Foo", "unittest:///foo.h", "\"foo.h\""}});
887889
TU.ExternalIndex = Index.get();
888890

889891
EXPECT_THAT(
@@ -908,7 +910,12 @@ void bar() {
908910
"no type named 'Global' in the global namespace"),
909911
DiagName("typename_nested_not_found"),
910912
WithFix(Fix(Test.range("insert"), "#include \"global.h\"\n",
911-
"Add include \"global.h\" for symbol Global")))));
913+
"Add include \"global.h\" for symbol Global"))),
914+
AllOf(Diag(Test.range("template"),
915+
"no template named 'Foo' in namespace 'ns'"),
916+
DiagName("no_member_template"),
917+
WithFix(Fix(Test.range("insert"), "#include \"foo.h\"\n",
918+
"Add include \"foo.h\" for symbol ns::Foo")))));
912919
}
913920

914921
TEST(IncludeFixerTest, MultipleMatchedSymbols) {

0 commit comments

Comments
 (0)