]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/20_util/function/6.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 6.cc
index 47d2c1f9bd72e3176dd1f479c069d6b20dbd9d19..55371b55c6d874505412f4b1b998dbbd27c8345c 100644 (file)
@@ -1,7 +1,9 @@
-// { dg-options "-std=gnu++0x" }
+// { dg-do run { target c++11 } }
+// { dg-require-effective-target hosted }
+
 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
 //
-// Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005-2024 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 #include <functional>
 #include <testsuite_hooks.h>
 
-using namespace __gnu_test;
+template<typename T>
+  const T&
+  as_const(T& t)
+  { return t; }
 
-bool test __attribute__((unused)) = true;
+// Check that f's target is a reference_wrapper bound to obj.
+template<typename Function, typename T>
+  bool
+  wraps(Function& f, T& obj)
+  {
+    using ref_wrapper_type = std::reference_wrapper<T>;
+    auto* p = f.template target<ref_wrapper_type>();
+    return std::addressof(p->get()) == std::addressof(obj);
+  }
 
 struct secret {};
 
@@ -54,25 +67,32 @@ void test06()
   function<int()> f(ref(x));
   VERIFY( f );
   VERIFY( f() == 17 );
-  VERIFY( f.target_type() == typeid(noncopyable_function_object_type) );
-  VERIFY( f.target<noncopyable_function_object_type>() == &x );
+#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 );
-  VERIFY( g.target_type() == typeid(noncopyable_function_object_type) );
-  VERIFY( g.target<noncopyable_function_object_type>() == &x );
+#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 );
-  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 );
+#if __cpp_rtti
+  VERIFY( h.target_type() == typeid(std::cref(x)) );
+#endif
+  VERIFY( wraps(h, as_const(x)) );
 
   const function<int()>& hc = h;
-  VERIFY( h.target<noncopyable_function_object_type>() == 0 );
-  VERIFY( hc.target<noncopyable_function_object_type>() == &x );
+#if __cpp_rtti
+  VERIFY( hc.target_type() == h.target_type() );
+#endif
+  VERIFY( wraps(hc, as_const(x)) );
 }
 
 int main()