public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/98835] False positive -Wclass-memaccess with class with ref-qualified copy-assignment operator
Date: Tue, 26 Jan 2021 19:38:53 +0000	[thread overview]
Message-ID: <bug-98835-4-ZJ31Pnkc8o@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98835-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98835

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning is issued on the basis that the left-hand operand of Bad's
assignment cannot be a temporary.  I.e., that this isn't valid: Bad() = Bad(). 
In the modified test case below the warning detects the memcpy call bypassing
the constraint the assignment operator puts on assigning to objects of the
class.  So unless there's a compelling use case showing otherwise I'm inclined
to say the warning is justified and helpful here (its wording shouldn't be
expected to perfectly reflect all the subtleties involved in the decision). 
There isn't a test case for this in the test suite so let me add this one.

  class Bad {
   public:
      Bad* operator& () { return this; }
      Bad & operator=(Bad const &) & = default;
  };

  template<typename T>
  void test() {
      static_assert (__has_trivial_copy (T));
      // T () = T ();                     // error
      memcpy (&T (), &T (), sizeof(T));   // warning
  }

  int main() {
      test<Bad>();
  }

  reply	other threads:[~2021-01-26 19:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  9:33 [Bug c++/98835] New: " jchl at arista dot com
2021-01-26 19:38 ` msebor at gcc dot gnu.org [this message]
2021-02-01 15:48 ` [Bug c++/98835] " cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98835-4-ZJ31Pnkc8o@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).