CWG 2094 partially reverts CWG 496, which means that volatile-qualified scalars are, once again, trivially copyable; [basic.types] now says "Scalar types, trivially copyable class types, arrays of such types, and cv-qualified versions of these types are collectively called trivially copyable types."
This previously changed in c++/63959 and this patch pretty much just reverts it. I'm CCing libstdc++ because a test in libstdc++ needed updating. Links to aforementioned CWGs: <http://wg21.link/cwg496> <http://wg21.link/cwg2094> Bootstrapped/regtested on x86_64-linux, ok for trunk? Not planning to backport this. 2019-05-19 Marek Polacek <pola...@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. * 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. diff --git gcc/gcc/cp/tree.c gcc/gcc/cp/tree.c index 8d7f7a2c3e7..821f2b79a67 100644 --- gcc/gcc/cp/tree.c +++ gcc/gcc/cp/tree.c @@ -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. */ + return scalarish_type_p (t); } /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and diff --git gcc/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C gcc/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C index 191b69601e6..d28f2f7b24e 100644 --- gcc/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C +++ gcc/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C @@ -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 gcc/gcc/testsuite/g++.dg/ext/is_trivially_copyable.C gcc/gcc/testsuite/g++.dg/ext/is_trivially_copyable.C new file mode 100644 index 00000000000..6f93602c8c2 --- /dev/null +++ gcc/gcc/testsuite/g++.dg/ext/is_trivially_copyable.C @@ -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[])); diff --git gcc/libstdc++-v3/testsuite/20_util/is_trivially_copyable/value.cc gcc/libstdc++-v3/testsuite/20_util/is_trivially_copyable/value.cc index cce620daf4d..022f0c0b248 100644 --- gcc/libstdc++-v3/testsuite/20_util/is_trivially_copyable/value.cc +++ gcc/libstdc++-v3/testsuite/20_util/is_trivially_copyable/value.cc @@ -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,