| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: mkdir -p %t |
| 3 |
// RUN: split-file %s %t |
| 4 |
// |
| 5 |
// RUN: %clang_cc1 -std=c++20 %t/typeinfo.cppm -emit-module-interface -o %t/typeinfo.pcm |
| 6 |
// RUN: %clang_cc1 -std=c++20 %t/typeid.cpp -fprebuilt-module-path=%t -fsyntax-only -verify |
| 7 |
|
| 8 |
// RUN: %clang_cc1 -std=c++20 %t/typeinfo.cppm -emit-reduced-module-interface -o %t/typeinfo.pcm |
| 9 |
// RUN: %clang_cc1 -std=c++20 %t/typeid.cpp -fprebuilt-module-path=%t -fsyntax-only -verify |
| 10 |
|
| 11 |
//--- typeinfo.h |
| 12 |
namespace std { |
| 13 |
class type_info { |
| 14 |
public: |
| 15 |
virtual ~type_info(); |
| 16 |
const char* name() const { return __name; } |
| 17 |
bool operator==(const type_info& __arg) const { |
| 18 |
return __name == __arg.__name; |
| 19 |
} |
| 20 |
|
| 21 |
bool operator!=(const type_info& __arg) const { |
| 22 |
return !operator==(__arg); |
| 23 |
} |
| 24 |
|
| 25 |
bool before(const type_info& __arg) const { |
| 26 |
return __name < __arg.__name; |
| 27 |
} |
| 28 |
|
| 29 |
unsigned long hash_code() const { |
| 30 |
return reinterpret_cast<unsigned long long>(__name); |
| 31 |
} |
| 32 |
protected: |
| 33 |
const char *__name; |
| 34 |
}; |
| 35 |
} |
| 36 |
|
| 37 |
//--- typeinfo.cppm |
| 38 |
module; |
| 39 |
#include "typeinfo.h"; |
| 40 |
export module typeinfo; |
| 41 |
export namespace std { |
| 42 |
using std::type_info; |
| 43 |
} |
| 44 |
|
| 45 |
//--- typeid.cpp |
| 46 |
// expected-no-diagnostics |
| 47 |
import typeinfo; |
| 48 |
|
| 49 |
class A { |
| 50 |
public: |
| 51 |
virtual void foo(); |
| 52 |
}; |
| 53 |
|
| 54 |
class B : public A { |
| 55 |
public: |
| 56 |
void foo() override; |
| 57 |
}; |
| 58 |
|
| 59 |
void A::foo() {} |
| 60 |
void B::foo() {} |
| 61 |
|
| 62 |
const auto &getTypeInfo() { |
| 63 |
return typeid(A); |
| 64 |
} |
| 65 |
|
| 66 |
const char *getName() { |
| 67 |
return typeid(A).name(); |
| 68 |
} |
| 69 |
|
| 70 |
bool equal(A *a) { |
| 71 |
return typeid(B) == typeid(*a); |
| 72 |
} |