diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-05-05 09:50:53 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-05-05 21:13:58 +0100 |
commit | b6b66006787b0991e94f15c7b5c56403f1eb85fb (patch) | |
tree | 18845b0f848d1cb6edcb7e866efb6e18a36ca2eb | |
parent | b06a79b82366a53fffc113f3bb5f873dbc70e381 (diff) | |
download | gcc-b6b66006787b0991e94f15c7b5c56403f1eb85fb.zip gcc-b6b66006787b0991e94f15c7b5c56403f1eb85fb.tar.gz gcc-b6b66006787b0991e94f15c7b5c56403f1eb85fb.tar.bz2 |
libstdc++: Fixes for tests that fail with -fno-rtti
This disables a use of dynamic_cast that is not valid for -fno-rtti and
adjusts some tests so they don't FAIL with -fno-rtti. Some tests are
skipped completely, and others just make use of typeid conditional on
the __cpp_rtti macro. A couple of tests were using typeid to verify
typedefs denote the right type, which can be done at compile-time using
templates instead.
libstdc++-v3/ChangeLog:
* include/experimental/memory_resource [!__cpp_rtti]
(__resource_adaptor_imp::do_is_equal): Do not use dynamic_cast
when RTTI is disabled.
* testsuite/17_intro/freestanding.cc: Require RTTI.
* testsuite/18_support/exception/38732.cc: Likewise.
* testsuite/18_support/exception_ptr/rethrow_exception.cc:
Likewise.
* testsuite/18_support/nested_exception/68139.cc: Likewise.
* testsuite/18_support/nested_exception/rethrow_if_nested.cc:
Likewise.
* testsuite/18_support/type_info/103240.cc: Likewise.
* testsuite/18_support/type_info/fundamental.cc: Likewise.
* testsuite/18_support/type_info/hash_code.cc: Likewise.
* testsuite/20_util/any/assign/emplace.cc: Likewise.
* testsuite/20_util/any/cons/in_place.cc: Likewise.
* testsuite/20_util/any/misc/any_cast.cc: Likewise.
* testsuite/20_util/any/observers/type.cc: Likewise.
* testsuite/20_util/function/1.cc: Likewise.
* testsuite/20_util/function/2.cc: Likewise.
* testsuite/20_util/function/3.cc: Likewise.
* testsuite/20_util/function/4.cc: Likewise.
* testsuite/20_util/function/5.cc: Likewise.
* testsuite/20_util/function/6.cc: Likewise.
* testsuite/20_util/function/7.cc: Likewise.
* testsuite/20_util/function/8.cc: Likewise.
* testsuite/20_util/polymorphic_allocator/resource.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/1.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/rval.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc:
Likewise.
* testsuite/20_util/shared_ptr/misc/get_deleter.cc: Likewise.
* testsuite/20_util/typeindex/comparison_operators.cc: Likewise.
* testsuite/20_util/typeindex/comparison_operators_c++20.cc:
Likewise.
* testsuite/20_util/typeindex/hash.cc: Likewise.
* testsuite/20_util/typeindex/hash_code.cc: Likewise.
* testsuite/20_util/typeindex/name.cc: Likewise.
* testsuite/22_locale/ctype/is/string/89728_neg.cc: Likewise.
* testsuite/22_locale/global_templates/standard_facet_hierarchies.cc:
Likewise.
* testsuite/22_locale/global_templates/user_facet_hierarchies.cc:
Likewise.
* testsuite/22_locale/locale/13630.cc: Check type without using
RTTI.
* testsuite/23_containers/array/requirements/non_default_constructible.cc:
Require RTTI.
* testsuite/27_io/basic_ostream/emit/1.cc: Likewise.
* testsuite/27_io/fpos/14320-1.cc: Check type without using RTTI.
* testsuite/27_io/fpos/mbstate_t/12065.cc: Require RTTI.
* testsuite/27_io/ios_base/failure/dual_abi.cc: Likewise.
* testsuite/experimental/any/misc/any_cast.cc: Likewise.
* testsuite/experimental/any/observers/type.cc: Likewise.
* testsuite/experimental/memory_resource/resource_adaptor.cc:
Likewise.
* testsuite/lib/libstdc++.exp (check_effective_target_rtti):
Define new proc.
* testsuite/tr1/3_function_objects/function/1.cc: Likewise.
* testsuite/tr1/3_function_objects/function/2.cc: Likewise.
* testsuite/tr1/3_function_objects/function/3.cc: Likewise.
* testsuite/tr1/3_function_objects/function/4.cc: Likewise.
* testsuite/tr1/3_function_objects/function/5.cc: Likewise.
* testsuite/tr1/3_function_objects/function/6.cc: Likewise.
* testsuite/tr1/3_function_objects/function/7.cc: Likewise.
* testsuite/tr1/3_function_objects/function/8.cc: Likewise.
* testsuite/tr2/bases/value.cc: Likewise.
* testsuite/tr2/direct_bases/value.cc: Likewise.
* testsuite/util/exception/safety.h [!__cpp_rtti]: Don't print
types without RTTI.
55 files changed, 284 insertions, 63 deletions
diff --git a/libstdc++-v3/include/experimental/memory_resource b/libstdc++-v3/include/experimental/memory_resource index 0785db8..d70a932 100644 --- a/libstdc++-v3/include/experimental/memory_resource +++ b/libstdc++-v3/include/experimental/memory_resource @@ -464,8 +464,13 @@ namespace pmr { virtual bool do_is_equal(const memory_resource& __other) const noexcept override { +#if __cpp_rtti if (auto __p = dynamic_cast<const __resource_adaptor_imp*>(&__other)) return _M_alloc == __p->_M_alloc; +#else + if (this == &__other) // Need RTTI to do better than this. + return true; +#endif return false; } diff --git a/libstdc++-v3/testsuite/17_intro/freestanding.cc b/libstdc++-v3/testsuite/17_intro/freestanding.cc index e82095f..ab87fb6 100644 --- a/libstdc++-v3/testsuite/17_intro/freestanding.cc +++ b/libstdc++-v3/testsuite/17_intro/freestanding.cc @@ -38,8 +38,10 @@ int main() { std::exception e; +#if __cpp_rtti const char* str __attribute__((unused)) = typeid(e).name(); - +#endif + typedef std::numeric_limits<long> limit_type; limit_type limit_l __attribute__((unused)); int r __attribute__((unused)) = limit_type::radix; diff --git a/libstdc++-v3/testsuite/18_support/exception/38732.cc b/libstdc++-v3/testsuite/18_support/exception/38732.cc index a388835..cccd420 100644 --- a/libstdc++-v3/testsuite/18_support/exception/38732.cc +++ b/libstdc++-v3/testsuite/18_support/exception/38732.cc @@ -68,21 +68,27 @@ void test01 () } catch(...) { __cxa_exception *exc = __cxa_get_globals()->caughtExceptions; VERIFY ( exc != 0 ); +#if __cpp_rtti VERIFY ( typeid(int) == *exc->exceptionType ); +#endif } try { throw 0LL; } catch(...) { __cxa_exception *exc = __cxa_get_globals()->caughtExceptions; VERIFY ( exc != 0 ); +#if __cpp_rtti VERIFY ( typeid(long long int) == *exc->exceptionType ); +#endif } try { throw 0.0; } catch(...) { __cxa_exception *exc = __cxa_get_globals()->caughtExceptions; VERIFY ( exc != 0 ); +#if __cpp_rtti VERIFY ( typeid(double) == *exc->exceptionType ); +#endif } } diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc index cb6676a..5e82d12 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc @@ -44,7 +44,9 @@ void test02() try { rethrow_exception(make_exception_ptr(runtime_error("test"))); } catch(exception &e) { +#if __cpp_rtti VERIFY( typeid(e) == typeid(runtime_error) ); +#endif VERIFY( strcmp(e.what(), "test") == 0 ); } } diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/68139.cc b/libstdc++-v3/testsuite/18_support/nested_exception/68139.cc index 42a9998..4abe459 100644 --- a/libstdc++-v3/testsuite/18_support/nested_exception/68139.cc +++ b/libstdc++-v3/testsuite/18_support/nested_exception/68139.cc @@ -1,4 +1,5 @@ // { dg-do compile { target c++11 } } +// { dg-require-effective-target rtti } // Copyright (C) 2015-2022 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc index 0e30b13..a10151c 100644 --- a/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc +++ b/libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // Copyright (C) 2009-2022 Free Software Foundation, Inc. // @@ -27,7 +28,7 @@ inline base::~base() noexcept = default; struct derived2 : base, std::nested_exception { }; -void test01() +void test01() { bool test = false; @@ -52,7 +53,7 @@ void test01() VERIFY( test ); } -void test02() +void test02() { bool test = false; @@ -69,7 +70,7 @@ void test02() VERIFY( test ); } -void test03() +void test03() { bool test = false; diff --git a/libstdc++-v3/testsuite/18_support/type_info/103240.cc b/libstdc++-v3/testsuite/18_support/type_info/103240.cc index 3d5968a..d2dd88d 100644 --- a/libstdc++-v3/testsuite/18_support/type_info/103240.cc +++ b/libstdc++-v3/testsuite/18_support/type_info/103240.cc @@ -1,5 +1,6 @@ // { dg-do run } // { dg-require-sharedlib "" } +// { dg-require-effective-target rtti } // { dg-options "./testsuite_shared.so" } #include <typeinfo> diff --git a/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc b/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc index a7b8ec4..34883c8 100644 --- a/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc +++ b/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc @@ -1,5 +1,6 @@ // { dg-do run { target c++11 } } // { dg-require-effective-target dfp } +// { dg-require-effective-target rtti } // 2011-02-23 Benjamin Kosnik <bkoz@redhat.com> // @@ -27,10 +28,10 @@ template<typename _Tp> std::string gen_type_info() - { - std::string s1 = typeid(_Tp).name(); - std::string s2 = typeid(_Tp*).name(); - std::string s3 = typeid(const _Tp*).name(); + { + std::string s1 = typeid(_Tp).name(); + std::string s2 = typeid(_Tp*).name(); + std::string s3 = typeid(const _Tp*).name(); return std::max(std::max(s1, s2), s3); } diff --git a/libstdc++-v3/testsuite/18_support/type_info/hash_code.cc b/libstdc++-v3/testsuite/18_support/type_info/hash_code.cc index ce5caa7..efbeb84 100644 --- a/libstdc++-v3/testsuite/18_support/type_info/hash_code.cc +++ b/libstdc++-v3/testsuite/18_support/type_info/hash_code.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // 2010-09-21 Paolo Carlini <paolo.carlini@oracle.com> // diff --git a/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc b/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc index 168377f..74885f9 100644 --- a/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc +++ b/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc @@ -58,6 +58,7 @@ int main() combined& c2 = std::any_cast<combined&>(o5); VERIFY(c2.v[0] == 1 && c2.v[1] == 2 && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); +#if __cpp_rtti std::any o6; o6.emplace<const int&>(i); VERIFY(o6.type() == o.type()); @@ -71,6 +72,7 @@ int main() std::any o10; o10.emplace<char*>(nullptr); VERIFY(o9.type() == o10.type()); +#endif std::any o11; VERIFY(&o11.emplace<int>(42) == &std::any_cast<int&>(o11)); VERIFY(&o11.emplace<std::vector<int>>({1,2,3}) == diff --git a/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc b/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc index fbcd58d..fabffe5 100644 --- a/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc +++ b/libstdc++-v3/testsuite/20_util/any/cons/in_place.cc @@ -53,6 +53,7 @@ int main() combined& c2 = std::any_cast<combined&>(o5); VERIFY(c2.v[0] == 1 && c2.v[1] == 2 && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); +#if __cpp_rtti std::any o6(std::in_place_type<int&>, i); VERIFY(o6.type() == o.type()); std::any o7(std::in_place_type<void()>, nullptr); @@ -61,4 +62,5 @@ int main() std::any o9(std::in_place_type<char(&)[42]>, nullptr); std::any o10(std::in_place_type<char*>, nullptr); VERIFY(o9.type() == o10.type()); +#endif } diff --git a/libstdc++-v3/testsuite/20_util/any/misc/any_cast.cc b/libstdc++-v3/testsuite/20_util/any/misc/any_cast.cc index 9241b0c..8d63dfb 100644 --- a/libstdc++-v3/testsuite/20_util/any/misc/any_cast.cc +++ b/libstdc++-v3/testsuite/20_util/any/misc/any_cast.cc @@ -157,13 +157,19 @@ void test07() { int arr[3]; any a(arr); +#if __cpp_rtti VERIFY( a.type() == typeid(int*) ); // contained value is decayed +#endif int (*p1)[3] = any_cast<int[3]>(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[3]) ); // so any_cast should return nullptr +#endif VERIFY( p1 == nullptr ); int (*p2)[] = any_cast<int[]>(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[]) ); // so any_cast should return nullptr +#endif VERIFY( p2 == nullptr ); const int (*p3)[] = any_cast<int[]>(&std::as_const(a)); VERIFY( p3 == nullptr ); diff --git a/libstdc++-v3/testsuite/20_util/any/observers/type.cc b/libstdc++-v3/testsuite/20_util/any/observers/type.cc index f8f5270..4d2f302 100644 --- a/libstdc++-v3/testsuite/20_util/any/observers/type.cc +++ b/libstdc++-v3/testsuite/20_util/any/observers/type.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++17 } } +// { dg-require-effective-target rtti } // Copyright (C) 2014-2022 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/function/1.cc b/libstdc++-v3/testsuite/20_util/function/1.cc index 65eef78..152b21f 100644 --- a/libstdc++-v3/testsuite/20_util/function/1.cc +++ b/libstdc++-v3/testsuite/20_util/function/1.cc @@ -73,8 +73,10 @@ void test01() } VERIFY( thrown ); +#if __cpp_rtti // target_type returns typeid(void) VERIFY( f1.target_type() == typeid(void) ); +#endif // target() always returns a NULL pointer VERIFY( f1.target<int (*)(float)>() == 0); diff --git a/libstdc++-v3/testsuite/20_util/function/2.cc b/libstdc++-v3/testsuite/20_util/function/2.cc index 6d33651..278dc89 100644 --- a/libstdc++-v3/testsuite/20_util/function/2.cc +++ b/libstdc++-v3/testsuite/20_util/function/2.cc @@ -62,7 +62,9 @@ void test02() // target_type and target() functions const function<int(float)>& f1c = f1; +#if __cpp_rtti VERIFY( typeid(int(*)(float)) == f1.target_type() ); +#endif VERIFY( f2.target<int(*)(float)>() != 0 ); VERIFY( *f2.target<int(*)(float)>() == &truncate_float ); VERIFY( f1c.target<int(*)(float)>() != 0 ); diff --git a/libstdc++-v3/testsuite/20_util/function/3.cc b/libstdc++-v3/testsuite/20_util/function/3.cc index f07966d..6257856 100644 --- a/libstdc++-v3/testsuite/20_util/function/3.cc +++ b/libstdc++-v3/testsuite/20_util/function/3.cc @@ -62,7 +62,9 @@ void test03() // target_type and target() functions const function<int(float)>& f1c = f1; +#if __cpp_rtti VERIFY( typeid(long(*)(double)) == f1.target_type() ); +#endif VERIFY( f2.target<long(*)(double)>() != 0 ); VERIFY( *f2.target<long(*)(double)>() == &truncate_double ); VERIFY( f1c.target<long(*)(double)>() != 0 ); diff --git a/libstdc++-v3/testsuite/20_util/function/4.cc b/libstdc++-v3/testsuite/20_util/function/4.cc index f5286ce..e2c098c 100644 --- a/libstdc++-v3/testsuite/20_util/function/4.cc +++ b/libstdc++-v3/testsuite/20_util/function/4.cc @@ -64,7 +64,9 @@ void test04() // target_type and target() functions const function<int(float)>& f1c = f1; +#if __cpp_rtti VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); +#endif VERIFY( f2.target<do_truncate_float_t>() != 0 ); VERIFY( f1c.target<do_truncate_float_t>() != 0 ); } diff --git a/libstdc++-v3/testsuite/20_util/function/5.cc b/libstdc++-v3/testsuite/20_util/function/5.cc index 338abb6..ccd4c32 100644 --- a/libstdc++-v3/testsuite/20_util/function/5.cc +++ b/libstdc++-v3/testsuite/20_util/function/5.cc @@ -36,64 +36,84 @@ void test05() function<int(X&)> frm(&X::bar); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); +#endif VERIFY( *frm.target<int X::*>() == &X::bar ); function<int(X&)> fr(&X::foo); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); +#endif VERIFY( *fr.target<int (X::*)()>() == &X::foo ); function<int(const X&)> frc(&X::foo_c); VERIFY( frc ); VERIFY( frc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == frc.target_type() ); +#endif VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c ); function<int(volatile X&)> frv(&X::foo_v); VERIFY( frv ); VERIFY( frv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); +#endif VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v ); VERIFY( frv.target<int (X::*)() const volatile>() == 0 ); function<int(const volatile X&)> frcv(&X::foo_cv); VERIFY( frcv ); VERIFY( frcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); +#endif VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv ); VERIFY( frcv.target<int (X::*)() const>() == 0 ); function<int(X*)> grm(&X::bar); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); +#endif VERIFY( *grm.target<int X::*>() == &X::bar ); function<int(X*)> gr(&X::foo); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); +#endif VERIFY( *gr.target<int (X::*)()>() == &X::foo ); function<int(const X*)> grc(&X::foo_c); VERIFY( grc ); VERIFY( grc(&x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == grc.target_type() ); +#endif VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c ); function<int(volatile X*)> grv(&X::foo_v); VERIFY( grv ); VERIFY( grv(&x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); +#endif VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v ); VERIFY( grv.target<int (X::*)() const volatile>() == 0 ); function<int(const volatile X*)> grcv(&X::foo_cv); VERIFY( grcv ); VERIFY( grcv(&x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); +#endif VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv ); VERIFY( grcv.target<int (X::*)() const>() == 0 ); } diff --git a/libstdc++-v3/testsuite/20_util/function/6.cc b/libstdc++-v3/testsuite/20_util/function/6.cc index eaeeb06..3eb9ef8 100644 --- a/libstdc++-v3/testsuite/20_util/function/6.cc +++ b/libstdc++-v3/testsuite/20_util/function/6.cc @@ -65,23 +65,31 @@ void test06() function<int()> f(ref(x)); VERIFY( f ); VERIFY( f() == 17 ); +#if __cpp_rtti VERIFY( f.target_type() == typeid(std::ref(x)) ); // LWG 2781 +#endif VERIFY( wraps(f, x) ); function<int()> g = f; VERIFY( g ); VERIFY( g() == 17 ); +#if __cpp_rtti VERIFY( g.target_type() == f.target_type() ); +#endif VERIFY( wraps(g, x) ); function<int()> h = cref(x); VERIFY( h ); VERIFY( h() == 42 ); +#if __cpp_rtti VERIFY( h.target_type() == typeid(std::cref(x)) ); +#endif VERIFY( wraps(h, as_const(x)) ); const function<int()>& hc = h; +#if __cpp_rtti VERIFY( hc.target_type() == h.target_type() ); +#endif VERIFY( wraps(hc, as_const(x)) ); } diff --git a/libstdc++-v3/testsuite/20_util/function/7.cc b/libstdc++-v3/testsuite/20_util/function/7.cc index 0617e3c..533232f 100644 --- a/libstdc++-v3/testsuite/20_util/function/7.cc +++ b/libstdc++-v3/testsuite/20_util/function/7.cc @@ -62,7 +62,9 @@ void test07() // target_type and target() functions const function<int(float)>& f1c = f1; using ref_wrapper_type = reference_wrapper<int(*)(float)>; +#if __cpp_rtti VERIFY( typeid(ref_wrapper_type) == f1.target_type() ); +#endif VERIFY( f1.target<ref_wrapper_type>() != nullptr ); VERIFY( wraps(f1, fptr) ); VERIFY( wraps(f1c, fptr) ); @@ -81,9 +83,13 @@ void test07() // target_type and target() functions const function<int(float)>& f2c = f2; using cref_wrapper_type = reference_wrapper<int(* const)(float)>; +#if __cpp_rtti VERIFY( typeid(cref_wrapper_type) == f2.target_type() ); +#endif VERIFY( wraps(f2, as_const(fptr)) ); +#if __cpp_rtti VERIFY( f2c.target_type() == f2.target_type() ); +#endif VERIFY( wraps(f2c, as_const(fptr)) ); } diff --git a/libstdc++-v3/testsuite/20_util/function/8.cc b/libstdc++-v3/testsuite/20_util/function/8.cc index 9770481..bd94e78 100644 --- a/libstdc++-v3/testsuite/20_util/function/8.cc +++ b/libstdc++-v3/testsuite/20_util/function/8.cc @@ -59,91 +59,121 @@ void test08() function<int(X&)> frm(ref(X_bar)); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(ref(X_bar)) == frm.target_type() ); +#endif VERIFY( wraps(frm, X_bar) ); function<int(X&)> fr(ref(X_foo)); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo)) == fr.target_type() ); +#endif VERIFY( wraps(fr, X_foo) ); function<int(const X&)> frc(ref(X_foo_c)); VERIFY( frc ); VERIFY( frc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_c)) == frc.target_type() ); +#endif VERIFY( wraps(frc, X_foo_c) ); function<int(volatile X&)> frv(ref(X_foo_v)); VERIFY( frv ); VERIFY( frv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_v)) == frv.target_type() ); +#endif VERIFY( wraps(frv, X_foo_v) ); function<int(const volatile X&)> frcv(ref(X_foo_cv)); VERIFY( frcv ); VERIFY( frcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_cv)) == frcv.target_type() ); +#endif VERIFY( wraps(frcv, X_foo_cv) ); function<int(X*)> grm(ref(X_bar)); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(ref(X_bar)) == grm.target_type() ); +#endif VERIFY( wraps(grm, X_bar) ); function<int(X*)> gr(ref(X_foo)); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo)) == gr.target_type() ); +#endif VERIFY( wraps(gr, X_foo) ); function<int(const X*)> grc(ref(X_foo_c)); VERIFY( grc ); VERIFY( grc(&x) == 2 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_c)) == grc.target_type() ); +#endif VERIFY( wraps(grc, X_foo_c) ); function<int(volatile X*)> grv(ref(X_foo_v)); VERIFY( grv ); VERIFY( grv(&x) == 3 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_v)) == grv.target_type() ); +#endif VERIFY( wraps(grv, X_foo_v) ); function<int(const volatile X*)> grcv(ref(X_foo_cv)); VERIFY( grcv ); VERIFY( grcv(&x) == 4 ); +#if __cpp_rtti VERIFY( typeid(ref(X_foo_cv)) == grcv.target_type() ); +#endif VERIFY( wraps(grcv, X_foo_cv) ); function<int(X&)> hrm(cref(X_bar)); VERIFY( hrm ); VERIFY( hrm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(cref(X_bar)) == hrm.target_type() ); +#endif VERIFY( wraps(hrm, as_const(X_bar)) ); function<int(X&)> hr(cref(X_foo)); VERIFY( hr ); VERIFY( hr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(cref(X_foo)) == hr.target_type() ); +#endif VERIFY( wraps(hr, as_const(X_foo)) ); function<int(const X&)> hrc(cref(X_foo_c)); VERIFY( hrc ); VERIFY( hrc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(cref(X_foo_c)) == hrc.target_type() ); +#endif VERIFY( wraps(hrc, as_const(X_foo_c)) ); function<int(volatile X&)> hrv(cref(X_foo_v)); VERIFY( hrv ); VERIFY( hrv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(cref(X_foo_v)) == hrv.target_type() ); +#endif VERIFY( wraps(hrv, as_const(X_foo_v)) ); function<int(const volatile X&)> hrcv(cref(X_foo_cv)); VERIFY( hrcv ); VERIFY( hrcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(cref(X_foo_cv)) == hrcv.target_type() ); +#endif VERIFY( wraps(hrcv, as_const(X_foo_cv)) ); } diff --git a/libstdc++-v3/testsuite/20_util/polymorphic_allocator/resource.cc b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/resource.cc index 5116b37..1e47641 100644 --- a/libstdc++-v3/testsuite/20_util/polymorphic_allocator/resource.cc +++ b/libstdc++-v3/testsuite/20_util/polymorphic_allocator/resource.cc @@ -41,7 +41,9 @@ test01() test_type c(&r2); VERIFY( c.resource() == &r2 ); VERIFY( c.resource() != a.resource() ); +#if __cpp_rtti VERIFY( c == a ); +#endif } void diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc index 450892f..a4fd959 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc @@ -41,7 +41,12 @@ test01() check_ret_type<shared_ptr<void>>(static_pointer_cast<void>(spd)); check_ret_type<shared_ptr<int>>(const_pointer_cast<int>(spci)); + // Non-polymorphic dynamic_cast works without RTTI. + check_ret_type<shared_ptr<MyP>>(dynamic_pointer_cast<MyP>(spa)); +#if __cpp_rtti + // But polymorphic dynamic_cast needs RTTI. check_ret_type<shared_ptr<MyDP>>(dynamic_pointer_cast<MyDP>(spa)); +#endif } void @@ -65,6 +70,7 @@ test02() VERIFY(pi.get() == ptr); VERIFY(pci.get() == ptr); +#if __cpp_rtti MyP* pptr = new MyP; shared_ptr<MyP> pp(pptr); auto pdp = dynamic_pointer_cast<MyDP>(pp); @@ -79,6 +85,7 @@ test02() VERIFY(pdp.use_count() == 2); VERIFY(pdp.get() == pptr); VERIFY(pp.get() == pptr); +#endif } int main() diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/casts/rval.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/rval.cc index 59b09f1..0178245 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/casts/rval.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/casts/rval.cc @@ -42,7 +42,10 @@ void test01() check_ret_type<shared_ptr<void>>(static_pointer_cast<void>(std::move(spd))); check_ret_type<shared_ptr<int>>(const_pointer_cast<int>(std::move(spci))); + check_ret_type<shared_ptr<MyP>>(dynamic_pointer_cast<MyP>(std::move(spa))); +#if __cpp_rtti check_ret_type<shared_ptr<MyDP>>(dynamic_pointer_cast<MyDP>(std::move(spa))); +#endif check_ret_type<shared_ptr<void>>(reinterpret_pointer_cast<void>(std::move(spd))); check_ret_type<shared_ptr<const short>>(reinterpret_pointer_cast<const short>(std::move(spci))); check_ret_type<shared_ptr<MyDP>>(reinterpret_pointer_cast<MyDP>(std::move(spa))); @@ -70,6 +73,7 @@ test02() VERIFY(pi.get() == ptr); VERIFY(pci.get() == nullptr); +#if __cpp_rtti MyP* pptr = new MyP; shared_ptr<MyP> pp(pptr); auto pdp = dynamic_pointer_cast<MyDP>(std::move(pp)); @@ -92,6 +96,7 @@ test02() VERIFY(pi.use_count() == 0); VERIFY(reinterpret_cast<int*>(pl.get()) == ptr); VERIFY(pi.get() == nullptr); +#endif } int main() diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc index d2d2900..5ef21fe 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc @@ -47,8 +47,12 @@ test01() typedef std::reference_wrapper<D> D2; D2* p3 = std::get_deleter<D2>(p2); +#if __cpp_rtti VERIFY( p3 != 0 ); VERIFY( &p3->get() == &d ); +#else + VERIFY( p3 == 0 ); // Always returns nullptr without RTTI. +#endif return 0; } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc index 6f262c8..1aab13f 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc @@ -32,7 +32,9 @@ test01() std::shared_ptr<int> p; VERIFY( std::get_deleter<Del>(p) == nullptr ); p = std::shared_ptr<int>(new int, Del()); +#if __cpp_rtti VERIFY( std::get_deleter<Del>(p) != nullptr ); +#endif p = std::shared_ptr<int>(new int); VERIFY( std::get_deleter<Del>(p) == nullptr ); } diff --git a/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc index 4beb2a3..616770f 100644 --- a/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc +++ b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators_c++20.cc b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators_c++20.cc index c75c82b..0610002 100644 --- a/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators_c++20.cc +++ b/libstdc++-v3/testsuite/20_util/typeindex/comparison_operators_c++20.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } +// { dg-require-effective-target rtti } // Copyright (C) 2020-2022 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/hash.cc b/libstdc++-v3/testsuite/20_util/typeindex/hash.cc index 12b2e2e..b0f1cc1 100644 --- a/libstdc++-v3/testsuite/20_util/typeindex/hash.cc +++ b/libstdc++-v3/testsuite/20_util/typeindex/hash.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc b/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc index 397755f..6b8659b 100644 --- a/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc +++ b/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/name.cc b/libstdc++-v3/testsuite/20_util/typeindex/name.cc index 9d53684..831b33a 100644 --- a/libstdc++-v3/testsuite/20_util/typeindex/name.cc +++ b/libstdc++-v3/testsuite/20_util/typeindex/name.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // 2010-09-22 Paolo Carlini <paolo.carlini@oracle.com> // diff --git a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc index 77bb1a6..7935c99 100644 --- a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc +++ b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "complete" "" { target *-*-* } 0 } +// { dg-error "invalid 'static_cast'" "" { target { ! rtti } } 0 } #include <locale> diff --git a/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc b/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc index fe55940..8f8762d 100644 --- a/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc +++ b/libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc @@ -40,8 +40,10 @@ int main() VERIFY( has_facet<base_facet>(loc_derived) ); // Standard derived facet. +#if __cpp_rtti VERIFY( !has_facet<derived_facet>(loc_c) ); VERIFY( !has_facet<derived_facet>(loc_base) ); +#endif VERIFY( has_facet<derived_facet>(loc_derived) ); diff --git a/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc b/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc index 9944605..3d499a3 100644 --- a/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc +++ b/libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc @@ -65,6 +65,7 @@ int main() // User defined derived facet. VERIFY( !has_facet<derived_facet>(loc_c) ); +#if __cpp_rtti VERIFY( !has_facet<derived_facet>(loc_base) ); VERIFY( has_facet<derived_facet>(loc_derived) ); @@ -97,6 +98,7 @@ int main() // Expect no exception. VERIFY( true ); } +#endif return 0; } diff --git a/libstdc++-v3/testsuite/22_locale/locale/13630.cc b/libstdc++-v3/testsuite/22_locale/locale/13630.cc index bffc9fd..b6bd0fd 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/13630.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/13630.cc @@ -17,19 +17,11 @@ // 22.1.1 class locale [lib.locale] -#include <locale> -#include <typeinfo> -#include <testsuite_hooks.h> +// { dg-do compile } -void test01() -{ - using namespace std; +#include <locale> - VERIFY( typeid(locale::category) == typeid(int) ); -} +template<typename, typename> struct SameType; +template<typename T> struct SameType<T, T> { }; -int main() -{ - test01(); - return 0; -} +SameType<std::locale::category, int> check; diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/non_default_constructible.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/non_default_constructible.cc index 4306a15..846a9fe 100644 --- a/libstdc++-v3/testsuite/23_containers/array/requirements/non_default_constructible.cc +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/non_default_constructible.cc @@ -1,4 +1,5 @@ // { dg-do compile { target c++11 } } +// { dg-require-effective-target rtti } // Copyright (C) 2012-2022 Free Software Foundation, Inc. // @@ -17,6 +18,8 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +// PR libstdc++/53248 + #include <array> #include <typeindex> #include <typeinfo> diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/emit/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/emit/1.cc index 0e18057..c1c8ae6 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostream/emit/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/emit/1.cc @@ -19,7 +19,7 @@ // { dg-additional-options "-pthread" { target pthread } } // { dg-do run { target c++2a } } // { dg-require-effective-target cxx11_abi } -// { dg-xfail-run-if "cannot catch forced_unwind" { *-*-* } { "-fno-rtti" } } +// { dg-require-effective-target rtti } #include <syncstream> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc index d6d9328..6614898 100644 --- a/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc @@ -19,46 +19,33 @@ // 27.4.3 fpos -// { dg-do run } +// { dg-do compile } -#include <typeinfo> #include <limits> #include <iterator> -#include <testsuite_hooks.h> // libstdc++/14320 -void test01() -{ - using namespace std; - typedef istreambuf_iterator<char>::difference_type Distance; - - bool found = false; - // The C++ standard didn't originally have "long long", however that - // type is in the C++11 standard and testing for it allows - // ilp32 targets to pass this test when `Distance' is 64 bits. - if (typeid(Distance) == typeid(long long int)) - found = true; - if (typeid(Distance) == typeid(long int)) - found = true; - if (typeid(Distance) == typeid(int)) - found = true; - if (typeid(Distance) == typeid(short int)) - found = true; - if (typeid(Distance) == typeid(signed char)) - found = true; - if (numeric_limits<char>::is_signed && - typeid(Distance) == typeid(char)) - found = true; - if (numeric_limits<wchar_t>::is_signed && - typeid(Distance) == typeid(wchar_t)) - found = true; - - VERIFY( found ); -} - -int main() -{ - test01(); - return 0; -} +typedef std::istreambuf_iterator<char>::difference_type Distance; + +#if __cplusplus >= 201103L + static_assert( std::is_integral<Distance>::value, "integral type" ); + static_assert( std::is_signed<Distance>::value, "signed integral type" ); +#else +template<typename> struct SignedInteger { enum { value = 0 }; }; +// The C++ standard didn't originally have "long long", however that +// type is in the C++11 standard and testing for it allows +// ilp32 targets to pass this test when `Distance' is 64 bits. +template<> struct SignedInteger<long long int> { enum { value = 1 }; }; +template<> struct SignedInteger<long int> { enum { value = 1 }; }; +template<> struct SignedInteger<int> { enum { value = 1 }; }; +template<> struct SignedInteger<short int> { enum { value = 1 }; }; +template<> struct SignedInteger<char> { + enum { value = std::numeric_limits<char>::is_signed }; +}; +template<> struct SignedInteger<wchar_t> { + enum { value = std::numeric_limits<wchar_t>::is_signed }; +}; + +char assertion[SignedInteger<Distance>::value ? 1 : -1]; +#endif diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc index ad774cd..276241e 100644 --- a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc @@ -15,6 +15,8 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +// { dg-require-effective-target rtti } + // 27.4.3 fpos #include <typeinfo> diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc index 84b8a16..8088ce1 100644 --- a/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc @@ -17,6 +17,7 @@ // { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" } // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } #include <fstream> #include <system_error> diff --git a/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc b/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc index e2ca71d..f3ce83a 100644 --- a/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc +++ b/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc @@ -36,7 +36,7 @@ void test01() any x(5); // x holds int VERIFY(any_cast<int>(x) == 5); // cast to value any_cast<int&>(x) = 10; // cast to reference - VERIFY(any_cast<int>(x) == 10); + VERIFY(any_cast<int>(x) == 10); x = "Meow"; // x holds const char* VERIFY(strcmp(any_cast<const char*>(x), "Meow") == 0); @@ -45,7 +45,7 @@ void test01() x = string("Meow"); // x holds string string s, s2("Jane"); - s = move(any_cast<string&>(x)); // move from any + s = move(any_cast<string&>(x)); // move from any VERIFY(s == "Meow"); any_cast<string&>(x) = move(s2); // move to any VERIFY(any_cast<const string&>(x) == "Jane"); @@ -153,13 +153,19 @@ void test07() { int arr[3]; any a(arr); +#if __cpp_rtti VERIFY( a.type() == typeid(int*) ); // contained value is decayed +#endif int (*p1)[3] = any_cast<int[3]>(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[3]) ); // so any_cast should return nullptr +#endif VERIFY( p1 == nullptr ); int (*p2)[] = any_cast<int[]>(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[]) ); // so any_cast should return nullptr +#endif VERIFY( p2 == nullptr ); const int (*p3)[] = any_cast<int[]>(&const_cast<const any&>(a)); VERIFY( p3 == nullptr ); diff --git a/libstdc++-v3/testsuite/experimental/any/observers/type.cc b/libstdc++-v3/testsuite/experimental/any/observers/type.cc index 1aa8a2c..f33ce56 100644 --- a/libstdc++-v3/testsuite/experimental/any/observers/type.cc +++ b/libstdc++-v3/testsuite/experimental/any/observers/type.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++14 } } +// { dg-require-effective-target rtti } // Copyright (C) 2014-2022 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc b/libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc index 7d74f78..91d2d16 100644 --- a/libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc +++ b/libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc @@ -59,7 +59,9 @@ test05() Allocator<int> a1(1), a2(2); // minimal interface allocators resource_adaptor<decltype(a1)> r1(a1), r2(a2); VERIFY( r1 == r1 ); +#if __cpp_rtti VERIFY( r1 == r2 ); +#endif p = r1.allocate(1); VERIFY( aligned<max_align_t>(p) ); r1.deallocate(p, 1); @@ -97,7 +99,9 @@ test05() __gnu_cxx::debug_allocator<std::allocator<short>> a5, a6; resource_adaptor<decltype(a5)> r5(a5), r6(a6); VERIFY( r5 == r5 ); +#if __cpp_rtti VERIFY( r5 == r6 ); +#endif VERIFY( r5 != r1 ); VERIFY( r5 != r3 ); p = r5.allocate(1); @@ -128,7 +132,9 @@ test05() __gnu_cxx::new_allocator<short> a7, a8; resource_adaptor<decltype(a7)> r7(a7), r8(a8); VERIFY( r7 == r7 ); +#if __cpp_rtti VERIFY( r7 == r8 ); +#endif VERIFY( r7 != r1 ); VERIFY( r7 != r3 ); VERIFY( r7 != r5 ); @@ -158,7 +164,9 @@ test05() __gnu_cxx::malloc_allocator<short> a9, a10; resource_adaptor<decltype(a9)> r9(a9), r10(a10); VERIFY( r9 == r9 ); +#if __cpp_rtti VERIFY( r9 == r10 ); +#endif VERIFY( r9 != r1 ); VERIFY( r9 != r3 ); VERIFY( r9 != r5 ); @@ -189,7 +197,9 @@ test05() std::allocator<short> a11, a12; resource_adaptor<decltype(a11)> r11(a11), r12(a12); VERIFY( r11 == r11 ); +#if __cpp_rtti VERIFY( r11 == r12 ); +#endif VERIFY( r11 != r1 ); VERIFY( r11 != r3 ); VERIFY( r11 != r5 ); diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 0debbea..93fdfee 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1354,6 +1354,14 @@ proc check_effective_target_stacktrace { } { }] } +# Return 1 if RTTI is enabled by the current test flags. +proc check_effective_target_rtti { } { + return [check_v3_target_prop_cached et_rtti { + set cond "__cpp_rtti" + return [v3_check_preprocessor_condition rtti $cond] + }] +} + set additional_prunes "" if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \ diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc index 035aabe9..b710f1e 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc @@ -73,6 +73,7 @@ void test01() } VERIFY( thrown ); +#if __cpp_rtti // target_type returns typeid(void) VERIFY( f1.target_type() == typeid(void) ); @@ -83,6 +84,7 @@ void test01() const function<int(float)>& f1c = f1; VERIFY( f1c.target<int (*)(float)>() == 0 ); VERIFY( !f1c ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc index 55a1f0b..e7aa9eb 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc @@ -59,6 +59,7 @@ void test02() f2 = truncate_float; VERIFY( f2(3.1f) == 3 ); +#if __cpp_rtti // target_type and target() functions const function<int(float)>& f1c = f1; VERIFY( typeid(int(*)(float)) == f1.target_type() ); @@ -66,6 +67,7 @@ void test02() VERIFY( *f2.target<int(*)(float)>() == &truncate_float ); VERIFY( f1c.target<int(*)(float)>() != 0 ); VERIFY( *f1c.target<int(*)(float)>() == &truncate_float ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc index 8d43a40..12492ba 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc @@ -59,6 +59,7 @@ void test03() f2 = truncate_double; VERIFY( f2(3.1f) == 3 ); +#if __cpp_rtti // target_type and target() functions const function<int(float)>& f1c = f1; VERIFY( typeid(long(*)(double)) == f1.target_type() ); @@ -66,6 +67,7 @@ void test03() VERIFY( *f2.target<long(*)(double)>() == &truncate_double ); VERIFY( f1c.target<long(*)(double)>() != 0 ); VERIFY( *f1c.target<long(*)(double)>() == &truncate_double ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc index 4a30511..dffd40f 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc @@ -61,11 +61,13 @@ void test04() f2 = do_truncate_float_t(); VERIFY( f2(3.1f) == 3 ); +#if __cpp_rtti // target_type and target() functions const function<int(float)>& f1c = f1; VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); VERIFY( f2.target<do_truncate_float_t>() != 0 ); VERIFY( f1c.target<do_truncate_float_t>() != 0 ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc index 8ef1351..58f7bea 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc @@ -35,66 +35,86 @@ void test05() function<int(X&)> frm(&X::bar); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); VERIFY( *frm.target<int X::*>() == &X::bar ); +#endif function<int(X&)> fr(&X::foo); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); VERIFY( *fr.target<int (X::*)()>() == &X::foo ); +#endif function<int(const X&)> frc(&X::foo_c); VERIFY( frc ); VERIFY( frc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == frc.target_type() ); VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c ); +#endif function<int(volatile X&)> frv(&X::foo_v); VERIFY( frv ); VERIFY( frv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v ); VERIFY( frv.target<int (X::*)() const volatile>() == 0 ); +#endif function<int(const volatile X&)> frcv(&X::foo_cv); VERIFY( frcv ); VERIFY( frcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv ); VERIFY( frcv.target<int (X::*)() const>() == 0 ); +#endif function<int(X*)> grm(&X::bar); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); VERIFY( *grm.target<int X::*>() == &X::bar ); +#endif function<int(X*)> gr(&X::foo); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); VERIFY( *gr.target<int (X::*)()>() == &X::foo ); +#endif function<int(const X*)> grc(&X::foo_c); VERIFY( grc ); VERIFY( grc(&x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == grc.target_type() ); VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c ); +#endif function<int(volatile X*)> grv(&X::foo_v); VERIFY( grv ); VERIFY( grv(&x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v ); VERIFY( grv.target<int (X::*)() const volatile>() == 0 ); +#endif function<int(const volatile X*)> grcv(&X::foo_cv); VERIFY( grcv ); VERIFY( grcv(&x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv ); VERIFY( grcv.target<int (X::*)() const>() == 0 ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc index d37dfc7..5dad3f0 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc @@ -52,18 +52,23 @@ void test06() function<int()> f(ref(x)); VERIFY( f ); VERIFY( f() == 17 ); +#if __cpp_rtti VERIFY( f.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( f.target<noncopyable_function_object_type>() == &x ); +#endif function<int()> g = f; VERIFY( g ); VERIFY( g() == 17 ); +#if __cpp_rtti VERIFY( g.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( g.target<noncopyable_function_object_type>() == &x ); +#endif function<int()> h = cref(x); VERIFY( h ); VERIFY( h() == 42 ); +#if __cpp_rtti VERIFY( h.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( h.target<const noncopyable_function_object_type>() == &x ); VERIFY( h.target<const noncopyable_function_object_type>() == &x ); @@ -71,6 +76,7 @@ void test06() const function<int()>& hc = h; VERIFY( h.target<noncopyable_function_object_type>() == 0 ); VERIFY( hc.target<noncopyable_function_object_type>() == &x ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc index 53a4ad6..9fc5997 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc @@ -44,6 +44,7 @@ void test07() // Invocation VERIFY( f1(3.1f) == 3 ); +#if __cpp_rtti // target_type and target() functions const function<int(float)>& f1c = f1; VERIFY( typeid(int(*)(float)) == f1.target_type() ); @@ -51,6 +52,7 @@ void test07() VERIFY( f1.target<int(*)(float)>() == &fptr ); VERIFY( f1c.target<int(*)(float)>() != 0 ); VERIFY( f1c.target<int(*)(float)>() == &fptr ); +#endif function<int(float)> f2(cref(fptr)); VERIFY( f2 ); @@ -63,6 +65,7 @@ void test07() // Invocation VERIFY( f2(3.1f) == 3 ); +#if __cpp_rtti // target_type and target() functions const function<int(float)>& f2c = f2; VERIFY( typeid(int(*)(float)) == f2.target_type() ); @@ -70,6 +73,7 @@ void test07() VERIFY( f2.target<int(* const)(float)>() == &fptr ); VERIFY( f2c.target<int(*)(float)>() != 0 ); VERIFY( f2c.target<int(*)(float)>() == &fptr ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc index 62b4e66..f13e2b2 100644 --- a/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc @@ -43,99 +43,129 @@ void test08() function<int(X&)> frm(ref(X_bar)); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); VERIFY( frm.target<int X::*>() == &X_bar ); +#endif function<int(X&)> fr(ref(X_foo)); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); VERIFY( fr.target<int (X::*)()>() == &X_foo ); +#endif function<int(const X&)> frc(ref(X_foo_c)); VERIFY( frc ); VERIFY( frc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == frc.target_type() ); VERIFY( frc.target<int (X::*)() const >() == &X_foo_c ); +#endif function<int(volatile X&)> frv(ref(X_foo_v)); VERIFY( frv ); VERIFY( frv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); VERIFY( *frv.target<int (X::*)() volatile >() == X_foo_v ); VERIFY( frv.target<int (X::*)() const volatile>() == 0 ); +#endif function<int(const volatile X&)> frcv(ref(X_foo_cv)); VERIFY( frcv ); VERIFY( frcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); VERIFY( *frcv.target<int (X::*)() const volatile >() == X_foo_cv ); VERIFY( frcv.target<int (X::*)() const>() == 0 ); +#endif function<int(X*)> grm(ref(X_bar)); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); VERIFY( *grm.target<int X::*>() == X_bar ); +#endif function<int(X*)> gr(ref(X_foo)); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); VERIFY( *gr.target<int (X::*)()>() == X_foo ); +#endif function<int(const X*)> grc(ref(X_foo_c)); VERIFY( grc ); VERIFY( grc(&x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == grc.target_type() ); VERIFY( *grc.target<int (X::*)() const >() == X_foo_c ); +#endif function<int(volatile X*)> grv(ref(X_foo_v)); VERIFY( grv ); VERIFY( grv(&x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); VERIFY( *grv.target<int (X::*)() volatile >() == X_foo_v ); VERIFY( grv.target<int (X::*)() const volatile>() == 0 ); +#endif function<int(const volatile X*)> grcv(ref(X_foo_cv)); VERIFY( grcv ); VERIFY( grcv(&x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); VERIFY( *grcv.target<int (X::*)() const volatile >() == X_foo_cv ); VERIFY( grcv.target<int (X::*)() const>() == 0 ); +#endif function<int(X&)> hrm(cref(X_bar)); VERIFY( hrm ); VERIFY( hrm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == hrm.target_type() ); VERIFY( hrm.target<int X::*>() == 0 ); VERIFY( hrm.target<int X::* const>() == &X_bar ); +#endif function<int(X&)> hr(cref(X_foo)); VERIFY( hr ); VERIFY( hr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == hr.target_type() ); VERIFY( hr.target<int (X::* const)()>() == &X_foo ); +#endif function<int(const X&)> hrc(cref(X_foo_c)); VERIFY( hrc ); VERIFY( hrc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == hrc.target_type() ); VERIFY( hrc.target<int (X::* const)() const >() == &X_foo_c ); +#endif function<int(volatile X&)> hrv(cref(X_foo_v)); VERIFY( hrv ); VERIFY( hrv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == hrv.target_type() ); VERIFY( hrv.target<int (X::* const)() volatile >() == &X_foo_v ); VERIFY( hrv.target<int (X::* const)() const volatile>() == 0 ); +#endif function<int(const volatile X&)> hrcv(cref(X_foo_cv)); VERIFY( hrcv ); VERIFY( hrcv(x) == 4 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const volatile) == hrcv.target_type() ); VERIFY( hrcv.target<int (X::* const)() const volatile >() == &X_foo_cv ); VERIFY( hrcv.target<int (X::* const)() const>() == 0 ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr2/bases/value.cc b/libstdc++-v3/testsuite/tr2/bases/value.cc index daecc9b..487541d 100644 --- a/libstdc++-v3/testsuite/tr2/bases/value.cc +++ b/libstdc++-v3/testsuite/tr2/bases/value.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // // Copyright (C) 2011-2022 Free Software Foundation, Inc. // @@ -67,7 +68,7 @@ void test() // Sanity check. static_assert(tl::empty::value != std::true_type::value, "!empty"); - + typedef tl::first::type tl1_first; typedef tl::rest::type tl2; typedef tl2::first::type tl2_first; diff --git a/libstdc++-v3/testsuite/tr2/direct_bases/value.cc b/libstdc++-v3/testsuite/tr2/direct_bases/value.cc index db5eff0..c55ffc7 100644 --- a/libstdc++-v3/testsuite/tr2/direct_bases/value.cc +++ b/libstdc++-v3/testsuite/tr2/direct_bases/value.cc @@ -1,4 +1,5 @@ // { dg-do run { target c++11 } } +// { dg-require-effective-target rtti } // // Copyright (C) 2011-2022 Free Software Foundation, Inc. // @@ -67,7 +68,7 @@ void test() // Sanity check. static_assert(tl::empty::value != std::true_type::value, "!empty"); - + typedef tl::first::type tl1_first; typedef tl::rest::type tl2; typedef tl2::first::type tl2_first; diff --git a/libstdc++-v3/testsuite/util/exception/safety.h b/libstdc++-v3/testsuite/util/exception/safety.h index db81a84..8ef9164 100644 --- a/libstdc++-v3/testsuite/util/exception/safety.h +++ b/libstdc++-v3/testsuite/util/exception/safety.h @@ -1459,7 +1459,11 @@ namespace __gnu_test while (!exit); // Log count info. +#if __cpp_rtti std::cout << __f.target_type().name() << std::endl; +#else + std::cout << "[no type info - rtti disabled]\n"; +#endif std::cout << "end count " << __step << std::endl; return __step; } @@ -1627,7 +1631,11 @@ namespace __gnu_test while (!exit); // Log count info. +#if __cpp_rtti std::cout << __f.target_type().name() << std::endl; +#else + std::cout << "[no type info - rtti disabled]\n"; +#endif std::cout << "end count " << i << std::endl; } }; |