From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by sourceware.org (Postfix) with ESMTPS id 7FB293858D3C for ; Thu, 5 May 2022 20:18:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7FB293858D3C Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-605-ZDjFNCCiM1KjOn-XGd7g2A-1; Thu, 05 May 2022 16:18:11 -0400 X-MC-Unique: ZDjFNCCiM1KjOn-XGd7g2A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D6533C01D85; Thu, 5 May 2022 20:18:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11102400F75E; Thu, 5 May 2022 20:18:10 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fixes for tests that fail with -fno-rtti Date: Thu, 5 May 2022 21:18:10 +0100 Message-Id: <20220505201810.3040654-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URI_HEX autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 20:18:19 -0000 Tested x86_64-linux -frtti/-fno-rtti, pushed to trunk. -- >8 -- 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. --- .../include/experimental/memory_resource | 5 ++ .../testsuite/17_intro/freestanding.cc | 4 +- .../testsuite/18_support/exception/38732.cc | 6 ++ .../exception_ptr/rethrow_exception.cc | 2 + .../18_support/nested_exception/68139.cc | 1 + .../nested_exception/rethrow_if_nested.cc | 7 ++- .../testsuite/18_support/type_info/103240.cc | 1 + .../18_support/type_info/fundamental.cc | 9 +-- .../18_support/type_info/hash_code.cc | 1 + .../testsuite/20_util/any/assign/emplace.cc | 2 + .../testsuite/20_util/any/cons/in_place.cc | 2 + .../testsuite/20_util/any/misc/any_cast.cc | 6 ++ .../testsuite/20_util/any/observers/type.cc | 1 + libstdc++-v3/testsuite/20_util/function/1.cc | 2 + libstdc++-v3/testsuite/20_util/function/2.cc | 2 + libstdc++-v3/testsuite/20_util/function/3.cc | 2 + libstdc++-v3/testsuite/20_util/function/4.cc | 2 + libstdc++-v3/testsuite/20_util/function/5.cc | 20 +++++++ libstdc++-v3/testsuite/20_util/function/6.cc | 8 +++ libstdc++-v3/testsuite/20_util/function/7.cc | 6 ++ libstdc++-v3/testsuite/20_util/function/8.cc | 30 ++++++++++ .../20_util/polymorphic_allocator/resource.cc | 2 + .../testsuite/20_util/shared_ptr/casts/1.cc | 7 +++ .../20_util/shared_ptr/casts/rval.cc | 5 ++ .../cons/unique_ptr_deleter_ref_2.cc | 4 ++ .../20_util/shared_ptr/misc/get_deleter.cc | 2 + .../20_util/typeindex/comparison_operators.cc | 1 + .../typeindex/comparison_operators_c++20.cc | 1 + .../testsuite/20_util/typeindex/hash.cc | 1 + .../testsuite/20_util/typeindex/hash_code.cc | 1 + .../testsuite/20_util/typeindex/name.cc | 1 + .../22_locale/ctype/is/string/89728_neg.cc | 1 + .../standard_facet_hierarchies.cc | 2 + .../user_facet_hierarchies.cc | 2 + .../testsuite/22_locale/locale/13630.cc | 18 ++---- .../requirements/non_default_constructible.cc | 3 + .../testsuite/27_io/basic_ostream/emit/1.cc | 2 +- libstdc++-v3/testsuite/27_io/fpos/14320-1.cc | 57 +++++++------------ .../testsuite/27_io/fpos/mbstate_t/12065.cc | 2 + .../27_io/ios_base/failure/dual_abi.cc | 1 + .../experimental/any/misc/any_cast.cc | 10 +++- .../experimental/any/observers/type.cc | 1 + .../memory_resource/resource_adaptor.cc | 10 ++++ libstdc++-v3/testsuite/lib/libstdc++.exp | 8 +++ .../tr1/3_function_objects/function/1.cc | 2 + .../tr1/3_function_objects/function/2.cc | 2 + .../tr1/3_function_objects/function/3.cc | 2 + .../tr1/3_function_objects/function/4.cc | 2 + .../tr1/3_function_objects/function/5.cc | 20 +++++++ .../tr1/3_function_objects/function/6.cc | 6 ++ .../tr1/3_function_objects/function/7.cc | 4 ++ .../tr1/3_function_objects/function/8.cc | 30 ++++++++++ libstdc++-v3/testsuite/tr2/bases/value.cc | 3 +- .../testsuite/tr2/direct_bases/value.cc | 3 +- .../testsuite/util/exception/safety.h | 8 +++ 55 files changed, 282 insertions(+), 61 deletions(-) diff --git a/libstdc++-v3/include/experimental/memory_resource b/libstdc++-v3/include/experimental/memory_resource index 0785db86f63..d70a93219fa 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(&__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 e82095fb482..ab87fb68157 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 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 a3888353a4b..cccd4209e14 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 cb6676aa870..5e82d12b7d0 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 42a99987ff1..4abe459d739 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 0e30b132d5f..a10151cc160 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 3d5968ac25c..d2dd88d42c8 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 diff --git a/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc b/libstdc++-v3/testsuite/18_support/type_info/fundamental.cc index a7b8ec4db92..34883c8cb15 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 // @@ -27,10 +28,10 @@ template 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 ce5caa76c5d..efbeb84a10c 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 // diff --git a/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc b/libstdc++-v3/testsuite/20_util/any/assign/emplace.cc index 168377f0493..74885f923e4 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(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(i); VERIFY(o6.type() == o.type()); @@ -71,6 +72,7 @@ int main() std::any o10; o10.emplace(nullptr); VERIFY(o9.type() == o10.type()); +#endif std::any o11; VERIFY(&o11.emplace(42) == &std::any_cast(o11)); VERIFY(&o11.emplace>({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 fbcd58df879..fabffe5a890 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(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, i); VERIFY(o6.type() == o.type()); std::any o7(std::in_place_type, nullptr); @@ -61,4 +62,5 @@ int main() std::any o9(std::in_place_type, nullptr); std::any o10(std::in_place_type, 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 9241b0c121c..8d63dfbba9b 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(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[3]) ); // so any_cast should return nullptr +#endif VERIFY( p1 == nullptr ); int (*p2)[] = any_cast(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[]) ); // so any_cast should return nullptr +#endif VERIFY( p2 == nullptr ); const int (*p3)[] = any_cast(&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 f8f52704961..4d2f302d31e 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 65eef78d1c4..152b21f6517 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() == 0); diff --git a/libstdc++-v3/testsuite/20_util/function/2.cc b/libstdc++-v3/testsuite/20_util/function/2.cc index 6d33651e035..278dc89736c 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& f1c = f1; +#if __cpp_rtti VERIFY( typeid(int(*)(float)) == f1.target_type() ); +#endif VERIFY( f2.target() != 0 ); VERIFY( *f2.target() == &truncate_float ); VERIFY( f1c.target() != 0 ); diff --git a/libstdc++-v3/testsuite/20_util/function/3.cc b/libstdc++-v3/testsuite/20_util/function/3.cc index f07966d998b..62578565978 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& f1c = f1; +#if __cpp_rtti VERIFY( typeid(long(*)(double)) == f1.target_type() ); +#endif VERIFY( f2.target() != 0 ); VERIFY( *f2.target() == &truncate_double ); VERIFY( f1c.target() != 0 ); diff --git a/libstdc++-v3/testsuite/20_util/function/4.cc b/libstdc++-v3/testsuite/20_util/function/4.cc index f5286ce008e..e2c098c1552 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& f1c = f1; +#if __cpp_rtti VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); +#endif VERIFY( f2.target() != 0 ); VERIFY( f1c.target() != 0 ); } diff --git a/libstdc++-v3/testsuite/20_util/function/5.cc b/libstdc++-v3/testsuite/20_util/function/5.cc index 338abb6783e..ccd4c327585 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 frm(&X::bar); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); +#endif VERIFY( *frm.target() == &X::bar ); function fr(&X::foo); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); +#endif VERIFY( *fr.target() == &X::foo ); function 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() == &X::foo_c ); function 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() == &X::foo_v ); VERIFY( frv.target() == 0 ); function 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() == &X::foo_cv ); VERIFY( frcv.target() == 0 ); function grm(&X::bar); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); +#endif VERIFY( *grm.target() == &X::bar ); function gr(&X::foo); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); +#endif VERIFY( *gr.target() == &X::foo ); function 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() == &X::foo_c ); function 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() == &X::foo_v ); VERIFY( grv.target() == 0 ); function 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() == &X::foo_cv ); VERIFY( grcv.target() == 0 ); } diff --git a/libstdc++-v3/testsuite/20_util/function/6.cc b/libstdc++-v3/testsuite/20_util/function/6.cc index eaeeb060c4d..3eb9ef86b25 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 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 g = f; VERIFY( g ); VERIFY( g() == 17 ); +#if __cpp_rtti VERIFY( g.target_type() == f.target_type() ); +#endif VERIFY( wraps(g, x) ); function 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& 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 0617e3cdc5d..533232f3729 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& f1c = f1; using ref_wrapper_type = reference_wrapper; +#if __cpp_rtti VERIFY( typeid(ref_wrapper_type) == f1.target_type() ); +#endif VERIFY( f1.target() != nullptr ); VERIFY( wraps(f1, fptr) ); VERIFY( wraps(f1c, fptr) ); @@ -81,9 +83,13 @@ void test07() // target_type and target() functions const function& f2c = f2; using cref_wrapper_type = reference_wrapper; +#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 9770481791f..bd94e78de24 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 5116b3737f7..1e47641f495 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 450892f0860..a4fd959137f 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>(static_pointer_cast(spd)); check_ret_type>(const_pointer_cast(spci)); + // Non-polymorphic dynamic_cast works without RTTI. + check_ret_type>(dynamic_pointer_cast(spa)); +#if __cpp_rtti + // But polymorphic dynamic_cast needs RTTI. check_ret_type>(dynamic_pointer_cast(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 pp(pptr); auto pdp = dynamic_pointer_cast(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 59b09f1082e..0178245c046 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>(static_pointer_cast(std::move(spd))); check_ret_type>(const_pointer_cast(std::move(spci))); + check_ret_type>(dynamic_pointer_cast(std::move(spa))); +#if __cpp_rtti check_ret_type>(dynamic_pointer_cast(std::move(spa))); +#endif check_ret_type>(reinterpret_pointer_cast(std::move(spd))); check_ret_type>(reinterpret_pointer_cast(std::move(spci))); check_ret_type>(reinterpret_pointer_cast(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 pp(pptr); auto pdp = dynamic_pointer_cast(std::move(pp)); @@ -92,6 +96,7 @@ test02() VERIFY(pi.use_count() == 0); VERIFY(reinterpret_cast(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 d2d290078f2..5ef21fe7154 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 D2; D2* p3 = std::get_deleter(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 6f262c817c1..1aab13f819c 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 p; VERIFY( std::get_deleter(p) == nullptr ); p = std::shared_ptr(new int, Del()); +#if __cpp_rtti VERIFY( std::get_deleter(p) != nullptr ); +#endif p = std::shared_ptr(new int); VERIFY( std::get_deleter(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 4beb2a31147..616770f5544 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 // 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 c75c82baafa..061000239ed 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 12b2e2ebdc3..b0f1cc16c69 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 // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc b/libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc index 397755f0638..6b8659bba77 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 // diff --git a/libstdc++-v3/testsuite/20_util/typeindex/name.cc b/libstdc++-v3/testsuite/20_util/typeindex/name.cc index 9d53684d78b..831b33ad4f6 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 // 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 77bb1a64f45..7935c99a96f 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 @@ // . // { dg-error "complete" "" { target *-*-* } 0 } +// { dg-error "invalid 'static_cast'" "" { target { ! rtti } } 0 } #include 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 fe559401de3..8f8762d8ff2 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(loc_derived) ); // Standard derived facet. +#if __cpp_rtti VERIFY( !has_facet(loc_c) ); VERIFY( !has_facet(loc_base) ); +#endif VERIFY( has_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 9944605e51b..3d499a347c1 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(loc_c) ); +#if __cpp_rtti VERIFY( !has_facet(loc_base) ); VERIFY( has_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 bffc9fdd81f..b6bd0fdffa5 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] +// { dg-do compile } + #include -#include -#include -void test01() -{ - using namespace std; +template struct SameType; +template struct SameType { }; - VERIFY( typeid(locale::category) == typeid(int) ); -} - -int main() -{ - test01(); - return 0; -} +SameType 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 4306a15814f..846a9fe8210 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 // . +// PR libstdc++/53248 + #include #include #include 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 0e18057557b..c1c8ae6dcaa 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 #include diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc index d6d93287ec9..661489806f8 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 #include #include -#include // libstdc++/14320 -void test01() -{ - using namespace std; - typedef istreambuf_iterator::difference_type Distance; +typedef std::istreambuf_iterator::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::is_signed && - typeid(Distance) == typeid(char)) - found = true; - if (numeric_limits::is_signed && - typeid(Distance) == typeid(wchar_t)) - found = true; - - VERIFY( found ); -} +#if __cplusplus >= 201103L + static_assert( std::is_integral::value, "integral type" ); + static_assert( std::is_signed::value, "signed integral type" ); +#else +template 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 { enum { value = 1 }; }; +template<> struct SignedInteger { enum { value = 1 }; }; +template<> struct SignedInteger { enum { value = 1 }; }; +template<> struct SignedInteger { enum { value = 1 }; }; +template<> struct SignedInteger { + enum { value = std::numeric_limits::is_signed }; +}; +template<> struct SignedInteger { + enum { value = std::numeric_limits::is_signed }; +}; -int main() -{ - test01(); - return 0; -} +char assertion[SignedInteger::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 ad774cdb4e4..276241eebbf 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 // . +// { dg-require-effective-target rtti } + // 27.4.3 fpos #include 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 84b8a16e1f6..8088ce1cbc9 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 #include diff --git a/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc b/libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc index e2ca71dbd46..f3ce83ad702 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(x) == 5); // cast to value any_cast(x) = 10; // cast to reference - VERIFY(any_cast(x) == 10); + VERIFY(any_cast(x) == 10); x = "Meow"; // x holds const char* VERIFY(strcmp(any_cast(x), "Meow") == 0); @@ -45,7 +45,7 @@ void test01() x = string("Meow"); // x holds string string s, s2("Jane"); - s = move(any_cast(x)); // move from any + s = move(any_cast(x)); // move from any VERIFY(s == "Meow"); any_cast(x) = move(s2); // move to any VERIFY(any_cast(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(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[3]) ); // so any_cast should return nullptr +#endif VERIFY( p1 == nullptr ); int (*p2)[] = any_cast(&a); +#if __cpp_rtti VERIFY( a.type() != typeid(int[]) ); // so any_cast should return nullptr +#endif VERIFY( p2 == nullptr ); const int (*p3)[] = any_cast(&const_cast(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 1aa8a2c03a4..f33ce564ee7 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 7d74f78da0f..91d2d1671d4 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 a1(1), a2(2); // minimal interface allocators resource_adaptor r1(a1), r2(a2); VERIFY( r1 == r1 ); +#if __cpp_rtti VERIFY( r1 == r2 ); +#endif p = r1.allocate(1); VERIFY( aligned(p) ); r1.deallocate(p, 1); @@ -97,7 +99,9 @@ test05() __gnu_cxx::debug_allocator> a5, a6; resource_adaptor 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 a7, a8; resource_adaptor 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 a9, a10; resource_adaptor 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 a11, a12; resource_adaptor 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 0debbea7ee1..93fdfee687d 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 035aabe9426..b710f1e31e9 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& f1c = f1; VERIFY( f1c.target() == 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 55a1f0b74b2..e7aa9eb89b2 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& f1c = f1; VERIFY( typeid(int(*)(float)) == f1.target_type() ); @@ -66,6 +67,7 @@ void test02() VERIFY( *f2.target() == &truncate_float ); VERIFY( f1c.target() != 0 ); VERIFY( *f1c.target() == &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 8d43a40cacc..12492ba5ace 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& f1c = f1; VERIFY( typeid(long(*)(double)) == f1.target_type() ); @@ -66,6 +67,7 @@ void test03() VERIFY( *f2.target() == &truncate_double ); VERIFY( f1c.target() != 0 ); VERIFY( *f1c.target() == &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 4a30511e92c..dffd40f7a68 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& f1c = f1; VERIFY( typeid(do_truncate_float_t) == f1.target_type() ); VERIFY( f2.target() != 0 ); VERIFY( f1c.target() != 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 8ef13512c62..58f7bea66f2 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 frm(&X::bar); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); VERIFY( *frm.target() == &X::bar ); +#endif function fr(&X::foo); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); VERIFY( *fr.target() == &X::foo ); +#endif function frc(&X::foo_c); VERIFY( frc ); VERIFY( frc(x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == frc.target_type() ); VERIFY( *frc.target() == &X::foo_c ); +#endif function frv(&X::foo_v); VERIFY( frv ); VERIFY( frv(x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); VERIFY( *frv.target() == &X::foo_v ); VERIFY( frv.target() == 0 ); +#endif function 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() == &X::foo_cv ); VERIFY( frcv.target() == 0 ); +#endif function grm(&X::bar); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); VERIFY( *grm.target() == &X::bar ); +#endif function gr(&X::foo); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); VERIFY( *gr.target() == &X::foo ); +#endif function grc(&X::foo_c); VERIFY( grc ); VERIFY( grc(&x) == 2 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() const) == grc.target_type() ); VERIFY( *grc.target() == &X::foo_c ); +#endif function grv(&X::foo_v); VERIFY( grv ); VERIFY( grv(&x) == 3 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); VERIFY( *grv.target() == &X::foo_v ); VERIFY( grv.target() == 0 ); +#endif function 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() == &X::foo_cv ); VERIFY( grcv.target() == 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 d37dfc7fc8b..5dad3f0b4b5 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 f(ref(x)); VERIFY( f ); VERIFY( f() == 17 ); +#if __cpp_rtti VERIFY( f.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( f.target() == &x ); +#endif function g = f; VERIFY( g ); VERIFY( g() == 17 ); +#if __cpp_rtti VERIFY( g.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( g.target() == &x ); +#endif function h = cref(x); VERIFY( h ); VERIFY( h() == 42 ); +#if __cpp_rtti VERIFY( h.target_type() == typeid(noncopyable_function_object_type) ); VERIFY( h.target() == &x ); VERIFY( h.target() == &x ); @@ -71,6 +76,7 @@ void test06() const function& hc = h; VERIFY( h.target() == 0 ); VERIFY( hc.target() == &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 53a4ad6b122..9fc59971b15 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& f1c = f1; VERIFY( typeid(int(*)(float)) == f1.target_type() ); @@ -51,6 +52,7 @@ void test07() VERIFY( f1.target() == &fptr ); VERIFY( f1c.target() != 0 ); VERIFY( f1c.target() == &fptr ); +#endif function 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& f2c = f2; VERIFY( typeid(int(*)(float)) == f2.target_type() ); @@ -70,6 +73,7 @@ void test07() VERIFY( f2.target() == &fptr ); VERIFY( f2c.target() != 0 ); VERIFY( f2c.target() == &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 62b4e667008..f13e2b2be6b 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 frm(ref(X_bar)); VERIFY( frm ); VERIFY( frm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == frm.target_type() ); VERIFY( frm.target() == &X_bar ); +#endif function fr(ref(X_foo)); VERIFY( fr ); VERIFY( fr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == fr.target_type() ); VERIFY( fr.target() == &X_foo ); +#endif function 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() == &X_foo_c ); +#endif function 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() == X_foo_v ); VERIFY( frv.target() == 0 ); +#endif function 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() == X_foo_cv ); VERIFY( frcv.target() == 0 ); +#endif function grm(ref(X_bar)); VERIFY( grm ); VERIFY( grm(&x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == grm.target_type() ); VERIFY( *grm.target() == X_bar ); +#endif function gr(ref(X_foo)); VERIFY( gr ); VERIFY( gr(&x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == gr.target_type() ); VERIFY( *gr.target() == X_foo ); +#endif function 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() == X_foo_c ); +#endif function 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() == X_foo_v ); VERIFY( grv.target() == 0 ); +#endif function 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() == X_foo_cv ); VERIFY( grcv.target() == 0 ); +#endif function hrm(cref(X_bar)); VERIFY( hrm ); VERIFY( hrm(x) == 17 ); +#if __cpp_rtti VERIFY( typeid(int X::*) == hrm.target_type() ); VERIFY( hrm.target() == 0 ); VERIFY( hrm.target() == &X_bar ); +#endif function hr(cref(X_foo)); VERIFY( hr ); VERIFY( hr(x) == 1 ); +#if __cpp_rtti VERIFY( typeid(int (X::*)()) == hr.target_type() ); VERIFY( hr.target() == &X_foo ); +#endif function 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() == &X_foo_c ); +#endif function 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() == &X_foo_v ); VERIFY( hrv.target() == 0 ); +#endif function 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() == &X_foo_cv ); VERIFY( hrcv.target() == 0 ); +#endif } int main() diff --git a/libstdc++-v3/testsuite/tr2/bases/value.cc b/libstdc++-v3/testsuite/tr2/bases/value.cc index daecc9be95a..487541da48b 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 db5eff02963..c55ffc7762e 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 db81a848746..8ef91648af6 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; } }; -- 2.34.1