[clang] [Clang][Diagnostics] Mention 'import std' in typeid diagnostic (PR #173236)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 22 02:08:39 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Yuki (AltriaSuki)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/173236.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1)
- (added) clang/test/SemaCXX/typeid-requires-typeinfo.cpp (+9)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/173236
More information about the cfe-commits
mailing list