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 // test type_info 10 11 // UNSUPPORTED: no-rtti 12 13 #include <typeinfo> 14 #include <string> 15 #include <cstring> 16 #include <cassert> 17 18 #include "test_macros.h" 19 test_constructor_explicit(std::type_info const &)20bool test_constructor_explicit(std::type_info const&) { return false; } test_constructor_explicit(std::string const &)21bool test_constructor_explicit(std::string const&) { return true; } 22 main(int,char **)23int main(int, char**) 24 { 25 { 26 const std::type_info& t1 = typeid(int); 27 const std::type_info& t2 = typeid(int); 28 assert(t1 == t2); 29 const std::type_info& t3 = typeid(short); 30 assert(t1 != t3); 31 assert(!t1.before(t2)); 32 assert(std::strcmp(t1.name(), t2.name()) == 0); 33 assert(std::strcmp(t1.name(), t3.name()) != 0); 34 } 35 { 36 // type_info has a protected constructor taking a string literal. This 37 // constructor is not intended for users. However it still participates 38 // in overload resolution, so we need to ensure that it is marked explicit 39 // to avoid ambiguous conversions. 40 // See: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=216201 41 assert(test_constructor_explicit("abc")); 42 } 43 44 return 0; 45 } 46