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: no-rtti 10 11 // In MSVC mode, the two anonymous types have identical type index in both object files. 12 // XFAIL: msvc 13 14 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu1.o -DTU1 -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1 15 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu2.o -DTU2 -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1 16 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.main.o -DMAIN -D_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION=1 17 // RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe 18 // RUN: %{exec} %t.exe 19 20 #include <cassert> 21 #include <typeindex> 22 #include <vector> 23 24 extern std::vector<std::type_index> registry; 25 26 void register1(); 27 void register2(); 28 29 #if defined(TU1) 30 namespace { struct A { bool x; }; } register1()31 void register1() { registry.push_back(std::type_index(typeid(A))); } 32 #elif defined(TU2) 33 namespace { struct A { int x, y; }; } register2()34 void register2() { registry.push_back(std::type_index(typeid(A))); } 35 #elif defined(MAIN) 36 std::vector<std::type_index> registry; 37 main(int,char **)38 int main(int, char**) { 39 register1(); 40 register2(); 41 42 assert(registry.size() == 2); 43 assert(registry[0] != registry[1]); 44 return 0; 45 } 46 #else 47 # error 48 #endif 49