]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fixes for tests that fail with -fno-rtti
authorJonathan Wakely <jwakely@redhat.com>
Thu, 5 May 2022 08:50:53 +0000 (09:50 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 5 May 2022 20:13:58 +0000 (21:13 +0100)
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:
libstdc++-v3/include/experimental/memory_resource
libstdc++-v3/testsuite/17_intro/freestanding.cc
libstdc++-v3/testsuite/18_support/exception/38732.cc
libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc
libstdc++-v3/testsuite/18_support/nested_exception/68139.cc
libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested.cc
libstdc++-v3/testsuite/18_support/type_info/103240.cc
libstdc++-v3/testsuite/18_support/type_info/fundamental.cc
libstdc++-v3/testsuite/18_support/type_info/hash_code.cc
libstdc++-v3/testsuite/20_util/any/assign/emplace.cc
libstdc++-v3/testsuite/20_util/any/cons/in_place.cc
libstdc++-v3/testsuite/20_util/any/misc/any_cast.cc
libstdc++-v3/testsuite/20_util/any/observers/type.cc
libstdc++-v3/testsuite/20_util/function/1.cc
libstdc++-v3/testsuite/20_util/function/2.cc
libstdc++-v3/testsuite/20_util/function/3.cc
libstdc++-v3/testsuite/20_util/function/4.cc
libstdc++-v3/testsuite/20_util/function/5.cc
libstdc++-v3/testsuite/20_util/function/6.cc
libstdc++-v3/testsuite/20_util/function/7.cc
libstdc++-v3/testsuite/20_util/function/8.cc
libstdc++-v3/testsuite/20_util/polymorphic_allocator/resource.cc
libstdc++-v3/testsuite/20_util/shared_ptr/casts/1.cc
libstdc++-v3/testsuite/20_util/shared_ptr/casts/rval.cc
libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc
libstdc++-v3/testsuite/20_util/shared_ptr/misc/get_deleter.cc
libstdc++-v3/testsuite/20_util/typeindex/comparison_operators.cc
libstdc++-v3/testsuite/20_util/typeindex/comparison_operators_c++20.cc
libstdc++-v3/testsuite/20_util/typeindex/hash.cc
libstdc++-v3/testsuite/20_util/typeindex/hash_code.cc
libstdc++-v3/testsuite/20_util/typeindex/name.cc
libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
libstdc++-v3/testsuite/22_locale/global_templates/standard_facet_hierarchies.cc
libstdc++-v3/testsuite/22_locale/global_templates/user_facet_hierarchies.cc
libstdc++-v3/testsuite/22_locale/locale/13630.cc
libstdc++-v3/testsuite/23_containers/array/requirements/non_default_constructible.cc
libstdc++-v3/testsuite/27_io/basic_ostream/emit/1.cc
libstdc++-v3/testsuite/27_io/fpos/14320-1.cc
libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc
libstdc++-v3/testsuite/27_io/ios_base/failure/dual_abi.cc
libstdc++-v3/testsuite/experimental/any/misc/any_cast.cc
libstdc++-v3/testsuite/experimental/any/observers/type.cc
libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc
libstdc++-v3/testsuite/lib/libstdc++.exp
libstdc++-v3/testsuite/tr1/3_function_objects/function/1.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/2.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/3.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/4.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/6.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/7.cc
libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc
libstdc++-v3/testsuite/tr2/bases/value.cc
libstdc++-v3/testsuite/tr2/direct_bases/value.cc
libstdc++-v3/testsuite/util/exception/safety.h

index 0785db86f637ddb72f2ab876d7ce998a0a3259bf..d70a93219faabd181649d6c674665ac9a2b72096 100644 (file)
@@ -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;
       }
 
index e82095fb482c13896f7646115e170bdf730a8fa3..ab87fb681572b5cb18b5a592bd80ee1d7074dc7f 100644 (file)
@@ -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;
index a3888353a4b43c4fea9537210fc2e9a8ecd3a555..cccd4209e149307dbe59b914f01a3fef240b91e6 100644 (file)
@@ -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
   }
 }
 
index cb6676aa8703f618e9b679cb487b3186944b2a4e..5e82d12b7d0f564238de4962972f7189a6f2110e 100644 (file)
@@ -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 );
   }
 }
index 42a99987ff179951518aa7b202a950896ec3775b..4abe459d73978d0ed16af310f6939f8dbd25ca5d 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do compile { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // Copyright (C) 2015-2022 Free Software Foundation, Inc.
 //
index 0e30b132d5f59222cd595a6958bb75b3860f72ce..a10151cc1603728492bd84e7ee2d56a5613f23a0 100644 (file)
@@ -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;
 
index 3d5968ac25cc830b7a8b572e3640518372541715..d2dd88d42c8cf8bde37c1699a250c3a0ffb10940 100644 (file)
@@ -1,5 +1,6 @@
 // { dg-do run }
 // { dg-require-sharedlib "" }
+// { dg-require-effective-target rtti }
 // { dg-options "./testsuite_shared.so" }
 
 #include <typeinfo>
index a7b8ec4db9204337b88fbb9d850359e8a7bb0668..34883c8cb1509a1396470a85955e0a568c59d059 100644 (file)
@@ -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>
 //
 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);
   }
 
index ce5caa76c5d2a30f2c6b995d7f335d9fe9d5f97d..efbeb84a10c166428c374f327379c98125a58dba 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // 2010-09-21  Paolo Carlini  <paolo.carlini@oracle.com>
 //
index 168377f0493cdcbde855ffb9643d35c95d7fc62b..74885f923e4f959d1e69d9b12a66c9df95d1ae2a 100644 (file)
@@ -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}) ==
index fbcd58df8792a36fca35fd478b44776efd70b878..fabffe5a890f2495c6fbf665f09da0e92fee798b 100644 (file)
@@ -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
 }
index 9241b0c121c3d6572135db6d47b407f900f0386f..8d63dfbba9b979e187f62de56c7764859580f3c7 100644 (file)
@@ -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 );
index f8f527049614ec7ad8c18e346d42252cee42180d..4d2f302d31eeef56f0fa2840c4d867a634f37c6b 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++17 } }
+// { dg-require-effective-target rtti }
 
 // Copyright (C) 2014-2022 Free Software Foundation, Inc.
 //
index 65eef78d1c4557bea0f9f241fc25d0282006c726..152b21f6517c58f34bc5e90d4654910f7cc7c163 100644 (file)
@@ -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);
index 6d33651e03599143c7afffe3aeccef2aa633cd50..278dc89736c488f950315b2a0c24e9831ca647e5 100644 (file)
@@ -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 );
index f07966d998b392a0cb74642a4f0cdaf8d67609c9..62578565978e51fd3f978aad358ead5544d36237 100644 (file)
@@ -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 );
index f5286ce008e443878b686561e03cabae925300fb..e2c098c1552b6715fd352bcecc7b131a3670151f 100644 (file)
@@ -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 );
 }
index 338abb6783ef1bda87177e8c913f906c5433b3d2..ccd4c327585e92412d9007fa4b507c5f90894c69 100644 (file)
@@ -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 );
 }
index eaeeb060c4ddf8f58d7dab4442f6ab24b9ccb772..3eb9ef86b253ff04d17d9bc8d692b8e197ecfef1 100644 (file)
@@ -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)) );
 }
 
index 0617e3cdc5dbe29c163bf590eddccbdbd77adbe2..533232f37291d341bae5eb5355eee05ee0890534 100644 (file)
@@ -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)) );
 }
 
index 9770481791f1b4c5d8e3135b10592551ed5d7cf4..bd94e78de24bd7f232ac3b1be5f48929feb48573 100644 (file)
@@ -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)) );
 }
 
index 5116b3737f7f3e43afee17b3028ed83177cb7878..1e47641f495bf85a8ba15dc3376d873a973aef59 100644 (file)
@@ -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
index 450892f0860007af4fa592846beeb8d651bc425e..a4fd959137f70d904f41df72d904addbe813846c 100644 (file)
@@ -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()
index 59b09f1082ed0f3b8a5dca5851b25a8b57d01ddf..0178245c0464c58a884ed28413a2d003b9f5a6ab 100644 (file)
@@ -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()
index d2d290078f2bab872e4c5f1e4c5cb63665d9cdc6..5ef21fe71541cdeb9e7fbd7ab74cde0f91952d30 100644 (file)
@@ -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;
 }
index 6f262c817c1c4df654f7742cbea2501887e35913..1aab13f819cbb0b453d14ba8ef8ef8ce06454639 100644 (file)
@@ -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 );
 }
index 4beb2a31147c8bd825c03825c2e60a19b7500036..616770f5544453ad44403baabc47bb8e82f42ea5 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // 2010-09-22  Paolo Carlini  <paolo.carlini@oracle.com>
 //
index c75c82baafa0773d58a970091cacff486a0fc2af..061000239ed88d549eb0bcbdacffe72f74c99259 100644 (file)
@@ -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.
 //
index 12b2e2ebdc3467358356cbd51b00f8281e75f6a1..b0f1cc16c69b11a3d4b903f3412b8c18e1a1c83f 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // 2010-09-22  Paolo Carlini  <paolo.carlini@oracle.com>
 //
index 397755f0638f3e24645fc637fc57b2b9ad23bd58..6b8659bba77f139c5b22a39cb505668a78728f59 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // 2010-09-22  Paolo Carlini  <paolo.carlini@oracle.com>
 //
index 9d53684d78b08b518007aafdfec08ac3c806b1c9..831b33ad4f6bbaad32aaff7ee8ddc4af2a7a2ca4 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target rtti }
 
 // 2010-09-22  Paolo Carlini  <paolo.carlini@oracle.com>
 //
index 77bb1a64f4518457c7330b136d62d7f55b1f6cc2..7935c99a96fd44c97a369d93bbec95fe9ff712dd 100644 (file)
@@ -18,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-error "complete" "" { target *-*-* } 0 }
+// { dg-error "invalid 'static_cast'" "" { target { ! rtti }  } 0 }
 
 #include <locale>
 
index fe559401de3e86d2dccd5a2221a4ff285dc16b3e..8f8762d8ff260614b0e773e76be0f5d753a881f4 100644 (file)
@@ -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) );
 
 
index 9944605e51b5df5e5d504246fc6920f4defe4260..3d499a347c1ab002ffad0f53e7a173c2ddcd5736 100644 (file)
@@ -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;
 }
index bffc9fdd81ffaf5aa7040cbf2dbbb297e90ea7b0..b6bd0fdffa53af2c85bb316e42a8df83cdca7793 100644 (file)
 
 // 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;
index 4306a15814f445f9c4bef2084788d6bdb4ac0e7f..846a9fe8210bf92bea6f09aaed8fb58dea30faf1 100644 (file)
@@ -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>
index 0e18057557b8b16143d6571fc5ea43ceeeb003c4..c1c8ae6dcaafc792c59b6d28a994faf8547f62c1 100644 (file)
@@ -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>
index d6d93287ec9eb44aa54dbc6a6cb60a6e5880cd94..661489806f8f8fef8a524ffb6e87a49b954dc000 100644 (file)
 
 // 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
index ad774cdb4e49dae0b1c1ac9b9f57c92e3f9d6248..276241eebbf5aeb3443e1a62f46c0ab1b4a58ea9 100644 (file)
@@ -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>
index 84b8a16e1f665a4505aa50e7db52b17adf540034..8088ce1cbc974137a5dc40cfe24f5bb8424bd3fe 100644 (file)
@@ -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>
index e2ca71dbd465d73de9bc0057966c29740cf53808..f3ce83ad7021dd8145bd8a1276c4dd11b27bf6bb 100644 (file)
@@ -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 );
index 1aa8a2c03a407bc002da90eb10db431b96e9e086..f33ce564ee779b1a860189d53193caa78638e999 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++14 } }
+// { dg-require-effective-target rtti }
 
 // Copyright (C) 2014-2022 Free Software Foundation, Inc.
 //
index 7d74f78da0f9d67a28a1a87ef53146f144966cf0..91d2d1671d4c9220d7314f623d33afdf218270d7 100644 (file)
@@ -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 );
index 0debbea7ee1814c61088ed1a2c709c2fc1196b87..93fdfee687ddb88cebe8f710be42e3624d70bbdc 100644 (file)
@@ -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)] \
index 035aabe9426190eb170d3743c17e50aa2c8cf9b3..b710f1e31e908f7681a32476b2a1aa4137cdd572 100644 (file)
@@ -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()
index 55a1f0b74b264dd664c40bd7fe31f4c7db632def..e7aa9eb89b20b66019aa56bf135e9395b81a759c 100644 (file)
@@ -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()
index 8d43a40cacc529b2089da79efd2d85606a204846..12492ba5aceacdf25b3785fa91f0b57fa8778494 100644 (file)
@@ -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()
index 4a30511e92c3248f105da42540906a4b7d4df21f..dffd40f7a68b1c5e00c03318a282e92310d97d1b 100644 (file)
@@ -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()
index 8ef13512c623f5c1a7c390f2b03cd46b76574193..58f7bea66f2a09adf3eb61efafe193783286496d 100644 (file)
@@ -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()
index d37dfc7fc8b9f31f3bc28e4be4e85112409c1156..5dad3f0b4b5bb95cc100bc93283231dcf3eae81e 100644 (file)
@@ -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()
index 53a4ad6b122e1840b608579a53514b3a195e49c2..9fc59971b15ab31f9d22576b6d7047d051f098df 100644 (file)
@@ -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()
index 62b4e6670087d74b8f9720e690257ec7ee4b50d8..f13e2b2be6b9d719567f4aef2e1e11e2ecd71bcd 100644 (file)
@@ -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()
index daecc9be95a4ab89d32fdc602e25eafd0c4488fb..487541da48b2073a6d1ef909ae0a795901b1df74 100644 (file)
@@ -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;
index db5eff02963f69bf73bef3f62fd7608b96b9bc51..c55ffc7762e2d13742db796a0a8a6b1d7ba1e3d4 100644 (file)
@@ -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;
index db81a848746777a144978342ef309b75b0b98f01..8ef91648af65701141a78684903bd986a57a04c9 100644 (file)
@@ -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;
        }
     };