CWG 2094 - volatile scalars are trivially copyable.
authorMarek Polacek <polacek@redhat.com>
Mon, 20 May 2019 19:10:57 +0000 (19:10 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 20 May 2019 19:10:57 +0000 (19:10 +0000)
PR c++/85679
* tree.c (trivially_copyable_p): Don't check CP_TYPE_VOLATILE_P for
scalar types.

* g++.dg/ext/is_trivially_constructible1.C: Change the expected result
for volatile int.
* g++.dg/ext/is_trivially_copyable.C: New test.

* testsuite/20_util/is_trivially_copyable/value.cc: Change the expected
result for volatile int.

From-SVN: r271435

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C
gcc/testsuite/g++.dg/ext/is_trivially_copyable.C [new file with mode: 0644]
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/20_util/is_trivially_copyable/value.cc

index 88275f0ed44acd300e43e4ba9b3f634eded8bc5c..f5f6c444436d5f1565e78b3492c10f7794c8a053 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-20  Marek Polacek  <polacek@redhat.com>
+
+       CWG 2094 - volatile scalars are trivially copyable.
+       PR c++/85679
+       * tree.c (trivially_copyable_p): Don't check CP_TYPE_VOLATILE_P for
+       scalar types.
+
 2019-05-20  Marek Polacek  <polacek@redhat.com>
 
        * pt.c (convert_template_argument): Add a diagnostic for the
index 8d7f7a2c3e74481f57530dd262d746a78642f29e..78139329476d78d5bd722cf9c9c88e4e171858ea 100644 (file)
@@ -4098,7 +4098,8 @@ trivially_copyable_p (const_tree t)
            && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
            && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
   else
-    return !CP_TYPE_VOLATILE_P (t) && scalarish_type_p (t);
+    /* CWG 2094 makes volatile-qualified scalars trivially copyable again.  */
+    return scalarish_type_p (t);
 }
 
 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
index be4e7eb895f4a64817c606bc80f9afd586bd65de..c100f6ae53e142ba6ff5a6efac2fa3218b33ffd0 100644 (file)
@@ -1,3 +1,11 @@
+2019-05-20  Marek Polacek  <polacek@redhat.com>
+
+       CWG 2094 - volatile scalars are trivially copyable.
+       PR c++/85679
+       * g++.dg/ext/is_trivially_constructible1.C: Change the expected result
+       for volatile int.
+       * g++.dg/ext/is_trivially_copyable.C: New test.
+
 2019-05-20  Marek Polacek  <polacek@redhat.com>
 
        * g++.dg/ext/utf8-2.C: Accept both "char" and "char8_t" in aka.
index 191b69601e68a6b2e3cbeb0049b16ec20fa2cea7..d28f2f7b24ede40bb247434d5b53962ef562a409 100644 (file)
@@ -48,7 +48,9 @@ SA(!__is_trivially_constructible(int*, const int*));
 SA(!__is_trivially_constructible(D));
 
 SA(__is_trivially_copyable(int));
-SA(!__is_trivially_copyable(volatile int));
+// Changed in CWG 2094, which made volatile-qualified scalars trivially
+// copyable.
+SA(__is_trivially_copyable(volatile int));
 
 struct E1 {const int val;};
 SA(__is_trivially_copyable(E1));
diff --git a/gcc/testsuite/g++.dg/ext/is_trivially_copyable.C b/gcc/testsuite/g++.dg/ext/is_trivially_copyable.C
new file mode 100644 (file)
index 0000000..6f93602
--- /dev/null
@@ -0,0 +1,16 @@
+// CWG 2094 - volatile scalars are trivially copyable.
+// PR c++/85679
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+struct S{};
+
+SA(__is_trivially_copyable(S volatile));
+SA(__is_trivially_copyable(S volatile[]));
+SA(__is_trivially_copyable(S const volatile));
+SA(__is_trivially_copyable(S const volatile[]));
+SA(__is_trivially_copyable(int volatile));
+SA(__is_trivially_copyable(int volatile[]));
+SA(__is_trivially_copyable(int const volatile));
+SA(__is_trivially_copyable(int const volatile[]));
index 98a676ec5c0595b4461007aaa82f8c705b4df28d..19ba2355c432971925cd88ced5182f87964df775 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-20  Marek Polacek  <polacek@redhat.com>
+
+       CWG 2094 - volatile scalars are trivially copyable.
+       PR c++/85679
+       * testsuite/20_util/is_trivially_copyable/value.cc: Change the expected
+       result for volatile int.
+
 2019-05-20  Jonathan Wakely  <jwakely@redhat.com>
 
        * testsuite/17_intro/names.cc: Do not check 'ptr' on Solaris.
index cce620daf4d570d445f01464d65a71ae6271e01a..022f0c0b248732893e41157bb3b3c072337d503d 100644 (file)
@@ -46,8 +46,10 @@ void test01()
 
   static_assert(test_property<is_trivially_copyable, 
                int>(true), "");
+  // Changed in CWG 2094, which made volatile-qualified scalars trivially
+  // copyable.
   static_assert(test_property<is_trivially_copyable,
-               volatile int>(false), "");
+               volatile int>(true), "");
   static_assert(test_property<is_trivially_copyable, 
                TType>(true), "");
   static_assert(test_property<is_trivially_copyable,