Author: Chuanqi Xu
Date: 2025-12-19T15:52:27+08:00
New Revision: 04638a76c1d8d572e56f3c8103bc642c4355fa7f

URL: 
https://github.com/llvm/llvm-project/commit/04638a76c1d8d572e56f3c8103bc642c4355fa7f
DIFF: 
https://github.com/llvm/llvm-project/commit/04638a76c1d8d572e56f3c8103bc642c4355fa7f.diff

LOG: [NFC] [C++20] [Modules] Adding test for typeinfo

Complained by https://github.com/llvm/llvm-project/issues/162758
but failed to reproduce.

Adding the reproducer as a test since I feel testing are always good.

Added: 
    clang/test/Modules/typeinfo.cppm

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/Modules/typeinfo.cppm 
b/clang/test/Modules/typeinfo.cppm
new file mode 100644
index 0000000000000..deaed0530a0a8
--- /dev/null
+++ b/clang/test/Modules/typeinfo.cppm
@@ -0,0 +1,72 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/typeinfo.cppm -emit-module-interface -o 
%t/typeinfo.pcm
+// RUN: %clang_cc1 -std=c++20 %t/typeid.cpp -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+// RUN: %clang_cc1 -std=c++20 %t/typeinfo.cppm -emit-reduced-module-interface 
-o %t/typeinfo.pcm
+// RUN: %clang_cc1 -std=c++20 %t/typeid.cpp -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+//--- typeinfo.h
+namespace std {
+class type_info {
+public:
+    virtual ~type_info();
+    const char* name() const { return __name; }
+    bool operator==(const type_info& __arg) const {
+    return __name == __arg.__name;
+    }
+
+    bool operator!=(const type_info& __arg) const {
+    return !operator==(__arg);
+    }
+
+    bool before(const type_info& __arg) const {
+    return __name < __arg.__name;
+    }
+
+    unsigned long hash_code() const {
+    return reinterpret_cast<unsigned long long>(__name);
+    }
+protected:
+    const char *__name;
+};
+}
+
+//--- typeinfo.cppm
+module;
+#include "typeinfo.h";
+export module typeinfo;
+export namespace std {
+    using std::type_info;
+}
+
+//--- typeid.cpp
+// expected-no-diagnostics
+import typeinfo;
+
+class A {
+public:
+    virtual void foo();
+};
+
+class B : public A {
+public:
+    void foo() override;
+};
+
+void A::foo() {}
+void B::foo() {}
+
+const auto &getTypeInfo() {
+    return typeid(A);
+}
+
+const char *getName() {
+    return typeid(A).name();
+}
+
+bool equal(A *a) {
+    return typeid(B) == typeid(*a);
+}


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

Reply via email to