https://github.com/AltriaSuki created 
https://github.com/llvm/llvm-project/pull/173236

Previously, the diagnostic only suggested including `<typeinfo>`. Since 
C++20,the standard library may also be made available via `import std;`.

This change updates the diagnostic to mention `import std` as an alternative 
and adds a test to cover the new wording.

>From e3b21647a8f9facebe13ecd4236cd3f7a72f2b3c Mon Sep 17 00:00:00 2001
From: feilun <[email protected]>
Date: Mon, 22 Dec 2025 18:04:49 +0800
Subject: [PATCH] [Clang][Diagnostics] Mention 'import std' in typeid
 diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/test/SemaCXX/typeid-requires-typeinfo.cpp  | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/typeid-requires-typeinfo.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 49eee0c2fa617..a8bff4d789b38 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8429,7 +8429,7 @@ def err_bad_dynamic_cast_not_polymorphic : Error<"%0 is 
not polymorphic">;
 
 // Other C++ expressions
 def err_need_header_before_typeid : Error<
-  "you need to include <typeinfo> before using the 'typeid' operator">;
+  "you need to include <typeinfo> or import std before using the 'typeid' 
operator">;
 def err_need_header_before_placement_new : Error<
   "no matching %0 function for non-allocating placement new expression; "
   "include <new>">;
diff --git a/clang/test/SemaCXX/typeid-requires-typeinfo.cpp 
b/clang/test/SemaCXX/typeid-requires-typeinfo.cpp
new file mode 100644
index 0000000000000..ec8773b438c28
--- /dev/null
+++ b/clang/test/SemaCXX/typeid-requires-typeinfo.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify 
-std=c++17 %s
+
+class A{};
+
+auto f() {
+  return typeid(A);
+}
+
+// CHECK: error: you need to include <typeinfo> or import std before using the 
'typeid' operator
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to