From c2f8e378d64f65645e5f9c41a8221ca102c71208 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 1 Feb 2021 08:42:58 -0700 Subject: [PATCH] Verify a warning for a class with a ref-qualified assignment (PR c++/98835). gcc/testsuite/ChangeLog: PR c++/98835 * g++.dg/Wclass-memaccess-6.C: New test. --- gcc/testsuite/g++.dg/Wclass-memaccess-6.C | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.dg/Wclass-memaccess-6.C diff --git a/gcc/testsuite/g++.dg/Wclass-memaccess-6.C b/gcc/testsuite/g++.dg/Wclass-memaccess-6.C new file mode 100644 index 00000000000..7f6fe03a939 --- /dev/null +++ b/gcc/testsuite/g++.dg/Wclass-memaccess-6.C @@ -0,0 +1,18 @@ +/* PR c++/98835 - -Wclass-memaccess with class with ref-qualified + copy-assignment operator + { dg-do compile { target { c++11 } } } + { dg-options "-Wall" } */ + +struct Bad +{ + Bad* operator& () { return this; } + Bad & operator=(Bad const &) & = default; +}; + +void test () +{ + static_assert (__has_trivial_copy (Bad)); + + // T () = T (); // error + __builtin_memcpy (&Bad (), &Bad (), sizeof (Bad)); // { dg-warning "\\\[-Wclass-memaccess" } +} -- 2.30.2