diff mbox

C++ PATCH for implicit move conditions (N3203)

Message ID 4EC53533.6060409@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 17, 2011, 4:24 p.m. UTC
At the Batavia meeting last year, the C++ committee changed the 
conditions for implicitly declaring move constructors/assignment ops; 
now they are suppressed by having any of (copy ctor/op=, move ctor/op=, 
dtor).  I needed to make some adjustments to the libstdc++ testsuite as 
a result; bkoz, do these changes make sense to you?

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 29f2248c817fa1469529c8c3089d742c25a0310f
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 16 14:25:23 2011 -0500

    	N3203
    	* class.c (add_implicitly_declared_members): Update move
    	conditions.

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 0765817..cb0e683 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2721,6 +2721,13 @@  add_implicitly_declared_members (tree t,
 				 int cant_have_const_cctor,
 				 int cant_have_const_assignment)
 {
+  bool move_ok = false;
+
+  if (cxx_dialect >= cxx0x && !CLASSTYPE_DESTRUCTORS (t)
+      && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
+      && !type_has_move_constructor (t) && !type_has_move_assign (t))
+    move_ok = true;
+
   /* Destructor.  */
   if (!CLASSTYPE_DESTRUCTORS (t))
     {
@@ -2758,7 +2765,7 @@  add_implicitly_declared_members (tree t,
       TYPE_HAS_COPY_CTOR (t) = 1;
       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
-      if (cxx_dialect >= cxx0x && !type_has_move_constructor (t))
+      if (move_ok)
 	CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
     }
 
@@ -2771,7 +2778,7 @@  add_implicitly_declared_members (tree t,
       TYPE_HAS_COPY_ASSIGN (t) = 1;
       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
-      if (cxx_dialect >= cxx0x && !type_has_move_assign (t))
+      if (move_ok)
 	CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
     }
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable2.cc
index 13cc4e5..2d1b4ca 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable2.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/char/moveable2.cc
@@ -31,6 +31,7 @@  class tstring : public std::basic_string<char>
 public:
   tstring() : std::basic_string<char>() {}
   tstring(tstring&& s) : std::basic_string<char>(std::move(s)) {}
+  tstring& operator=(tstring&& s) = default;
 };
 
 void test01()
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc
index e0b8b24..42026c9 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc
@@ -31,6 +31,7 @@  class twstring : public std::basic_string<wchar_t>
 public:
   twstring() : std::basic_string<wchar_t>() {}
   twstring(twstring&& s) : std::basic_string<wchar_t>(std::move(s)) {}
+  twstring& operator=(twstring&&) = default;
 };
 
 void test01()
diff --git a/libstdc++-v3/testsuite/util/testsuite_tr1.h b/libstdc++-v3/testsuite/util/testsuite_tr1.h
index f063896..1452e3e 100644
--- a/libstdc++-v3/testsuite/util/testsuite_tr1.h
+++ b/libstdc++-v3/testsuite/util/testsuite_tr1.h
@@ -199,6 +199,7 @@  namespace __gnu_test
   struct NoexceptMoveConsClass
   {
     NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
+    NoexceptMoveConsClass& operator=(NoexceptMoveConsClass&&) = default;
   };
 
   struct ExceptMoveConsClass
@@ -220,6 +221,7 @@  namespace __gnu_test
 
   struct NoexceptMoveAssignClass
   {
+    NoexceptMoveAssignClass(NoexceptMoveAssignClass&&) = default;
     NoexceptMoveAssignClass&
     operator=(NoexceptMoveAssignClass&&) noexcept(true);
   };