[PATCH] D141218: [clangd] Include the correct header for typeid()

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 8 00:18:53 PST 2023


nridge created this revision.
nridge added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1449


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141218

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ 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 <typeinfo> before using "
+                             "the 'typeid' operator"),
+          withFix(Fix(Test.range("insert"), "#include <typeinfo>\n",
+                      "Include <typeinfo>")))));
+}
+
 TEST(DiagsInHeaders, DiagInsideHeader) {
   Annotations Main(R"cpp(
     #include [["a.h"]]
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
     return only(insertHeader("<initializer_list>"));
   case diag::err_need_header_before_typeid:
-    return only(insertHeader("<typeid>"));
+    return only(insertHeader("<typeinfo>"));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
     return only(insertHeader("<new>"));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141218.487148.patch
Type: text/x-patch
Size: 1681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230108/61f54969/attachment.bin>


More information about the cfe-commits mailing list