diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -225,7 +225,7 @@ case diag::err_implied_std_initializer_list_not_found: return only(insertHeader("")); case diag::err_need_header_before_typeid: - return only(insertHeader("")); + return only(insertHeader("")); case diag::err_need_header_before_placement_new: case diag::err_implicit_coroutine_std_nothrow_type_not_found: return only(insertHeader("")); diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -1528,6 +1528,24 @@ "Include \"foo.h\" for symbol foo"))))); } +TEST(IncludeFixerTest, Typeid) { + Annotations Test(R"cpp( + $insert[[]]void func() { + [[typeid]](int); // error-ok + } + )cpp"); + auto TU = TestTU::withCode(Test.code()); + auto Index = buildIndexWithSymbol({}); + TU.ExternalIndex = Index.get(); + EXPECT_THAT( + *TU.build().getDiagnostics(), + ElementsAre(AllOf( + Diag(Test.range(), "you need to include before using " + "the 'typeid' operator"), + withFix(Fix(Test.range("insert"), "#include \n", + "Include "))))); +} + TEST(DiagsInHeaders, DiagInsideHeader) { Annotations Main(R"cpp( #include [["a.h"]]