This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[C++0x] std::exception_ptr rvalues
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 15 Jun 2009 20:36:57 +0100
- Subject: [C++0x] std::exception_ptr rvalues
n2884 removed support for swapping with rvalues everywhere in the
library, but I missed exception_ptr::swap() when I changed libstdc++.
The symbol is not exported so it can just be removed.
exception_ptr's move assignment operator doesn't actually move right
now: a temporary is copy-constructed then swapped with *this. This
patch casts the source to an rvalue-reference, ensuring the temporary
is move-constructed instead, avoiding a reference count update.
* libsupc++/exception_ptr.h (exception_ptr::swap(exception_ptr&&)):
Remove.
(exception_ptr::operator=(exception_ptr&&)): Cast source to
rvalue-reference so that move constructor is called.
* testsuite/18_support/exception_ptr/move.cc: New.
As noted in the new file, the test checks for behaviour that is not
required, but is a property of this implementation that I think should
be tested.
Tested x86_64-unknown-linux-gnu, OK for trunk? Should this go on the
4.4. branch too?
Jonathan
Index: libsupc++/exception_ptr.h
===================================================================
--- libsupc++/exception_ptr.h (revision 148467)
+++ libsupc++/exception_ptr.h (working copy)
@@ -123,7 +123,7 @@ namespace std
exception_ptr&
operator=(exception_ptr&& __o) throw()
{
- exception_ptr(__o).swap(*this);
+ exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this);
return *this;
}
#endif
@@ -133,16 +133,6 @@ namespace std
void
swap(exception_ptr&) throw();
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- void
- swap(exception_ptr &&__o) throw()
- {
- void *__tmp = _M_exception_object;
- _M_exception_object = __o._M_exception_object;
- __o._M_exception_object = __tmp;
- }
-#endif
-
#ifdef _GLIBCXX_EH_PTR_COMPAT
// Retained for compatibility with CXXABI_1.3.
bool operator!() const throw() __attribute__ ((__pure__));
Index: testsuite/18_support/exception_ptr/move.cc
===================================================================
--- testsuite/18_support/exception_ptr/move.cc (revision 0)
+++ testsuite/18_support/exception_ptr/move.cc (revision 0)
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <exception>
+#include <utility>
+#include <testsuite_hooks.h>
+
+// Verify move construction and assignment are efficient and do not copy.
+// This behaviour is a GNU extension provided for efficiency.
+void test01()
+{
+ bool test = true;
+
+ std::exception_ptr p1 = std::copy_exception(test);
+ std::exception_ptr p2 = std::move(p1);
+ VERIFY( p1 == 0 );
+ VERIFY( !(p2 == 0) );
+
+ p1 = std::move(p2);
+ VERIFY( !(p1 == 0) );
+ VERIFY( p2 == 0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}