re PR c++/64489 (A simple struct wrapping a const int is not trivially copyable)
authorVille Voutilainen <ville.voutilainen@gmail.com>
Tue, 6 Jan 2015 20:44:32 +0000 (22:44 +0200)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 6 Jan 2015 20:44:32 +0000 (15:44 -0500)
PR c++/64489
* class.c (check_field_decls): Make copy assignment operators
complex only in c++98 mode.

From-SVN: r219265

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C

index 004629b884897ba5479bcdf0dfd40d533dcbfc58..9c0159f812bf546b57fe2e315d09a5930d2b2404 100644 (file)
@@ -1,3 +1,9 @@
+2015-01-06  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       PR c++/64489
+       * class.c (check_field_decls): Make copy assignment operators
+       complex only in c++98 mode.
+
 2015-01-05  Trevor Saunders  <tsaunders@mozilla.com>
 
        PR c++/31397
index b798a52702fd9f5010c5e86c45d666310353c3f8..2153a73241a3201b1240df9b79658c63e15ee067 100644 (file)
@@ -3607,13 +3607,15 @@ check_field_decls (tree t, tree *access_decls,
          CLASSTYPE_NON_STD_LAYOUT (t) = 1;
          if (DECL_INITIAL (x) == NULL_TREE)
            SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
-
-         /* ARM $12.6.2: [A member initializer list] (or, for an
-            aggregate, initialization by a brace-enclosed list) is the
-            only way to initialize nonstatic const and reference
-            members.  */
-         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
-         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
+         if (cxx_dialect < cxx11)
+           {
+             /* ARM $12.6.2: [A member initializer list] (or, for an
+                aggregate, initialization by a brace-enclosed list) is the
+                only way to initialize nonstatic const and reference
+                members.  */
+             TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
+             TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
+           }
        }
 
       type = strip_array_types (type);
@@ -3715,13 +3717,15 @@ check_field_decls (tree t, tree *access_decls,
          C_TYPE_FIELDS_READONLY (t) = 1;
          if (DECL_INITIAL (x) == NULL_TREE)
            SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
-
-         /* ARM $12.6.2: [A member initializer list] (or, for an
-            aggregate, initialization by a brace-enclosed list) is the
-            only way to initialize nonstatic const and reference
-            members.  */
-         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
-         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
+         if (cxx_dialect < cxx11)
+           {
+             /* ARM $12.6.2: [A member initializer list] (or, for an
+                aggregate, initialization by a brace-enclosed list) is the
+                only way to initialize nonstatic const and reference
+                members.  */
+             TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
+             TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
+           }
        }
       /* A field that is pseudo-const makes the structure likewise.  */
       else if (CLASS_TYPE_P (type))
index c8663739e7dbe56d66fc891c08ac234757997c7f..a5bac7b482e58c1f5d71380e3647edab938ba7d6 100644 (file)
@@ -36,3 +36,8 @@ SA(!__is_trivially_constructible(D));
 
 SA(__is_trivially_copyable(int));
 SA(!__is_trivially_copyable(volatile int));
+
+struct E1 {const int val;};
+SA(__is_trivially_copyable(E1));
+struct E2 {int& val;};
+SA(__is_trivially_copyable(E2));