public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95772] New: warning desired when default operator= cannot be constructued
@ 2020-06-19 20:14 marcpawl at gmail dot com
  2020-06-19 20:30 ` [Bug c++/95772] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: marcpawl at gmail dot com @ 2020-06-19 20:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95772
           Summary: warning desired when default operator= cannot be
                    constructued
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcpawl at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/eXckPe

#include <type_traits>

class Const {
 public:
  int const i_;

  Const(int i) : i_(i) {}

  Const& operator=(Const& rhs) = default;
};

int main(int argc, char**) {
  Const c{argc};
  static_assert(!std::is_assignable<Const, Const>::value,
                "should not be able to assign i_");
#ifdef ASSIGN
  Const d{argc + 1};
  d = c;
#endif
  return c.i_;
}

I expected a diagnostic saying that operator= cannot be defaulted which is seen
if the ASSIGN code is enabled.  The code compiles cleanly.

When I wrote this bug in a large code base  with -03 and -flto the code will
fail with illegal instructions and other memory corruption errors.  No problem
without optimization.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/95772] warning desired when default operator= cannot be constructued
  2020-06-19 20:14 [Bug c++/95772] New: warning desired when default operator= cannot be constructued marcpawl at gmail dot com
@ 2020-06-19 20:30 ` redi at gcc dot gnu.org
  2020-06-19 23:59 ` marcpawl at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-19 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Pawlowsky from comment #0)
> I expected a diagnostic saying that operator= cannot be defaulted which is
> seen if the ASSIGN code is enabled.  The code compiles cleanly.

As expected. The C++ standard is clear about what this code means. The
explicitly defaulted assignment operator is defined as deleted, because it
would be ill-formed.

Defaulting it doesn't mean it will be provided by the compiler.


> When I wrote this bug in a large code base  with -03 and -flto the code will
> fail with illegal instructions and other memory corruption errors.  No
> problem without optimization.

What bug? The type is not assignable, how can that fail at runtime?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/95772] warning desired when default operator= cannot be constructued
  2020-06-19 20:14 [Bug c++/95772] New: warning desired when default operator= cannot be constructued marcpawl at gmail dot com
  2020-06-19 20:30 ` [Bug c++/95772] " redi at gcc dot gnu.org
@ 2020-06-19 23:59 ` marcpawl at gmail dot com
  2020-06-20 14:28 ` redi at gcc dot gnu.org
  2020-06-20 17:52 ` marcpawl at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: marcpawl at gmail dot com @ 2020-06-19 23:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc Pawlowsky <marcpawl at gmail dot com> ---
I understand that it is deleted, but if somebody says it should be defaulted
when it is defaulted that is most likely an error, and it would be nice if a
warning were generated.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/95772] warning desired when default operator= cannot be constructued
  2020-06-19 20:14 [Bug c++/95772] New: warning desired when default operator= cannot be constructued marcpawl at gmail dot com
  2020-06-19 20:30 ` [Bug c++/95772] " redi at gcc dot gnu.org
  2020-06-19 23:59 ` marcpawl at gmail dot com
@ 2020-06-20 14:28 ` redi at gcc dot gnu.org
  2020-06-20 17:52 ` marcpawl at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-20 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, =default means "do the right thing" which sometimes means deleting it.

In class templates that is especially true, where you don't know the properties
of the types used as data members or base classes.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/95772] warning desired when default operator= cannot be constructued
  2020-06-19 20:14 [Bug c++/95772] New: warning desired when default operator= cannot be constructued marcpawl at gmail dot com
                   ` (2 preceding siblings ...)
  2020-06-20 14:28 ` redi at gcc dot gnu.org
@ 2020-06-20 17:52 ` marcpawl at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: marcpawl at gmail dot com @ 2020-06-20 17:52 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Pawlowsky <marcpawl at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Marc Pawlowsky <marcpawl at gmail dot com> ---
"Do the default thing" vs "generate the default".  

What would your feeling be for a clang-tidy rule under readability?  It was a
surprise to me, especially since I never have actually read the spec since
C++98, just training articles/videos and quick scans through the odd committee
paper.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-20 17:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-19 20:14 [Bug c++/95772] New: warning desired when default operator= cannot be constructued marcpawl at gmail dot com
2020-06-19 20:30 ` [Bug c++/95772] " redi at gcc dot gnu.org
2020-06-19 23:59 ` marcpawl at gmail dot com
2020-06-20 14:28 ` redi at gcc dot gnu.org
2020-06-20 17:52 ` marcpawl at gmail dot com

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).