public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96501] New: [C++11] Should warn when classes only have copy constructor defined
@ 2020-08-06 14:31 nunoplopes at sapo dot pt
  2020-08-06 16:44 ` [Bug c++/96501] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: nunoplopes at sapo dot pt @ 2020-08-06 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96501
           Summary: [C++11] Should warn when classes only have copy
                    constructor defined
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nunoplopes at sapo dot pt
  Target Milestone: ---

I see a lot of old code that has copy constructors defined, but not move
constructors. This pessimizes code since the definition of the copy constructor
hides the default move constructor.
Would be nice to get a warning for this to recover perf.

```
#include <utility>
using namespace std;

struct foo {
  int a,b,c;
  // expect-warning
  foo(const foo &);
};

foo fn(foo &&f) {
  foo g(move(f));
  return g;
}
```

https://gcc.godbolt.org/z/5r8erG

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

* [Bug c++/96501] [C++11] Should warn when classes only have copy constructor defined
  2020-08-06 14:31 [Bug c++/96501] New: [C++11] Should warn when classes only have copy constructor defined nunoplopes at sapo dot pt
@ 2020-08-06 16:44 ` redi at gcc dot gnu.org
  2020-08-06 17:29 ` redi at gcc dot gnu.org
  2021-05-19 16:13 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-06 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Nuno Lopes from comment #0)
> I see a lot of old code that has copy constructors defined, but not move
> constructors. This pessimizes code since the definition of the copy
> constructor hides the default move constructor.

If you need a user-defined copy constructor, a defaulted move constructor
probably isn't going to do the right thing anyway.

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

* [Bug c++/96501] [C++11] Should warn when classes only have copy constructor defined
  2020-08-06 14:31 [Bug c++/96501] New: [C++11] Should warn when classes only have copy constructor defined nunoplopes at sapo dot pt
  2020-08-06 16:44 ` [Bug c++/96501] " redi at gcc dot gnu.org
@ 2020-08-06 17:29 ` redi at gcc dot gnu.org
  2021-05-19 16:13 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-06 17:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also, how would users suppress this warning for cases where it's not wanted?

Plenty of classes don't need a move constructor because moving is not more
efficient than copying, but they don't want a defaulted move constructor.

Basically, the code isn't necessarily wrong, and there's no easy way to tell
whether the lack of a move constructor is a problem, or should be changed.

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

* [Bug c++/96501] [C++11] Should warn when classes only have copy constructor defined
  2020-08-06 14:31 [Bug c++/96501] New: [C++11] Should warn when classes only have copy constructor defined nunoplopes at sapo dot pt
  2020-08-06 16:44 ` [Bug c++/96501] " redi at gcc dot gnu.org
  2020-08-06 17:29 ` redi at gcc dot gnu.org
@ 2021-05-19 16:13 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-19 16:13 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a dup, and there's additional discussion in the dup.

*** This bug has been marked as a duplicate of bug 89700 ***

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

end of thread, other threads:[~2021-05-19 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 14:31 [Bug c++/96501] New: [C++11] Should warn when classes only have copy constructor defined nunoplopes at sapo dot pt
2020-08-06 16:44 ` [Bug c++/96501] " redi at gcc dot gnu.org
2020-08-06 17:29 ` redi at gcc dot gnu.org
2021-05-19 16:13 ` redi at gcc dot gnu.org

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