Loading libcxx/include/typeinfo +3 −2 Original line number Diff line number Diff line Loading @@ -95,12 +95,13 @@ protected: uintptr_t __type_name; _LIBCPP_INLINE_VISIBILITY type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {} explicit type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {} #else const char *__type_name; _LIBCPP_INLINE_VISIBILITY type_info(const char* __n) : __type_name(__n) {} explicit type_info(const char* __n) : __type_name(__n) {} #endif public: Loading libcxx/test/std/language.support/support.rtti/type.info/type_info.pass.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -10,10 +10,15 @@ // test type_info #include <typeinfo> #include <string> #include <cstring> #include <cassert> bool test_constructor_explicit(std::type_info const&) { return false; } bool test_constructor_explicit(std::string const&) { return true; } int main() { { const std::type_info& t1 = typeid(int); const std::type_info& t2 = typeid(int); Loading @@ -24,3 +29,12 @@ int main() assert(strcmp(t1.name(), t2.name()) == 0); assert(strcmp(t1.name(), t3.name()) != 0); } { // type_info has a protected constructor taking a string literal. This // constructor is not intended for users. However it still participates // in overload resolution, so we need to ensure that it is marked explicit // to avoid ambiguous conversions. // See: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=216201 assert(test_constructor_explicit("abc")); } } Loading
libcxx/include/typeinfo +3 −2 Original line number Diff line number Diff line Loading @@ -95,12 +95,13 @@ protected: uintptr_t __type_name; _LIBCPP_INLINE_VISIBILITY type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {} explicit type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {} #else const char *__type_name; _LIBCPP_INLINE_VISIBILITY type_info(const char* __n) : __type_name(__n) {} explicit type_info(const char* __n) : __type_name(__n) {} #endif public: Loading
libcxx/test/std/language.support/support.rtti/type.info/type_info.pass.cpp +14 −0 Original line number Diff line number Diff line Loading @@ -10,10 +10,15 @@ // test type_info #include <typeinfo> #include <string> #include <cstring> #include <cassert> bool test_constructor_explicit(std::type_info const&) { return false; } bool test_constructor_explicit(std::string const&) { return true; } int main() { { const std::type_info& t1 = typeid(int); const std::type_info& t2 = typeid(int); Loading @@ -24,3 +29,12 @@ int main() assert(strcmp(t1.name(), t2.name()) == 0); assert(strcmp(t1.name(), t3.name()) != 0); } { // type_info has a protected constructor taking a string literal. This // constructor is not intended for users. However it still participates // in overload resolution, so we need to ensure that it is marked explicit // to avoid ambiguous conversions. // See: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=216201 assert(test_constructor_explicit("abc")); } }