1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: -fno-rtti
10 
11 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu1.o -DTU1 -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1
12 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu2.o -DTU2 -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1
13 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.main.o -DMAIN -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1
14 // RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
15 // RUN: %{exec} %t.exe
16 
17 #include <cassert>
18 #include <typeindex>
19 #include <vector>
20 
21 extern std::vector<std::type_index> registry;
22 
23 void register1();
24 void register2();
25 
26 #if defined(TU1)
27   namespace { struct A { bool x; }; }
register1()28   void register1() { registry.push_back(std::type_index(typeid(A))); }
29 #elif defined(TU2)
30   namespace { struct A { int x, y; }; }
register2()31   void register2() { registry.push_back(std::type_index(typeid(A))); }
32 #elif defined(MAIN)
33   std::vector<std::type_index> registry;
34 
main()35   int main() {
36     register1();
37     register2();
38 
39     assert(registry.size() == 2);
40     assert(registry[0] != registry[1]);
41   }
42 #else
43 # error
44 #endif
45