Bug 88136 - -Wdeprecated-copy is draconian and shouldn't be in -Wall
Summary: -Wdeprecated-copy is draconian and shouldn't be in -Wall
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: lto
: P3 normal
Target Milestone: 9.0
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2018-11-21 14:05 UTC by Ville Voutilainen
Modified: 2023-12-19 20:48 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-11-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ville Voutilainen 2018-11-21 14:05:54 UTC
Consider code like this:

struct X
{
protected:
    ~X() {}
};

struct Y : X 
{
    Y() = default;
    Y(const Y& other) : X(other) {}
};

int main()
{
    Y y;
    Y y2 = y;
}

gcc 9 warns about it, because X has a user-provided destructor. However, in
this particular case, and in cases where the implicitly-defaulted copy/move
are fine but the destructor does some extra work and is thus user-provided, the compiler will warn.

The warning completely shatters the ability to build Qt.
Comment 1 Richard Biener 2018-11-21 14:34:14 UTC
We've been there before with -Wexpansion-to-defined though.
Comment 2 Ville Voutilainen 2018-11-21 14:59:56 UTC
This is not just a Qt problem. I will write a proposal to undeprecate this deprecation for C++20 before the next committee meeting.
Comment 3 Eric Gallager 2018-11-21 16:31:39 UTC
(In reply to Richard Biener from comment #1)
> We've been there before with -Wexpansion-to-defined though.

That's only in -Wextra and -Wpedantic, though, not -Wall, so it's not exactly the same.
Comment 4 Jason Merrill 2018-12-06 21:17:40 UTC
Author: jason
Date: Thu Dec  6 21:17:08 2018
New Revision: 266867

URL: https://gcc.gnu.org/viewcvs?rev=266867&root=gcc&view=rev
Log:
	PR c++/88136 - -Wdeprecated-copy false positives

Deprecating the copy operations because the class has a user-provided
destructor turns out to have too many false positives; this patch adjusts
-Wdeprecated-copy to only deprecate if the other copy operation is
user-provided.  To get the earlier behavior, people can explicitly request
it with -Wdeprecated-copy-dtor.

gcc/c-family/
	* c.opt (Wdeprecated-copy-dtor): New.
	(Wdeprecated-copy): Move to -Wextra.
gcc/cp/
	* class.c (classtype_has_depr_implicit_copy): Rename from
	classtype_has_user_copy_or_dtor.
	* method.c (lazily_declare_fn): Adjust.
	* decl2.c (cp_warn_deprecated_use): Refer to -Wdeprecated-copy-dtor
	if deprecation is due to a destructor.

Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/method.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/g++.dg/cpp0x/depr-copy1.C
Comment 5 Eric Gallager 2019-03-09 05:34:35 UTC
(In reply to Jason Merrill from comment #4)
> Author: jason
> Date: Thu Dec  6 21:17:08 2018
> New Revision: 266867
> 
> URL: https://gcc.gnu.org/viewcvs?rev=266867&root=gcc&view=rev
> Log:
> 	PR c++/88136 - -Wdeprecated-copy false positives
> 
> Deprecating the copy operations because the class has a user-provided
> destructor turns out to have too many false positives; this patch adjusts
> -Wdeprecated-copy to only deprecate if the other copy operation is
> user-provided.  To get the earlier behavior, people can explicitly request
> it with -Wdeprecated-copy-dtor.
> 
> gcc/c-family/
> 	* c.opt (Wdeprecated-copy-dtor): New.
> 	(Wdeprecated-copy): Move to -Wextra.
> gcc/cp/
> 	* class.c (classtype_has_depr_implicit_copy): Rename from
> 	classtype_has_user_copy_or_dtor.
> 	* method.c (lazily_declare_fn): Adjust.
> 	* decl2.c (cp_warn_deprecated_use): Refer to -Wdeprecated-copy-dtor
> 	if deprecation is due to a destructor.
> 
> Modified:
>     trunk/gcc/c-family/ChangeLog
>     trunk/gcc/c-family/c.opt
>     trunk/gcc/cp/ChangeLog
>     trunk/gcc/cp/class.c
>     trunk/gcc/cp/cp-tree.h
>     trunk/gcc/cp/decl2.c
>     trunk/gcc/cp/method.c
>     trunk/gcc/doc/invoke.texi
>     trunk/gcc/testsuite/g++.dg/cpp0x/depr-copy1.C

so... FIXED now?
Comment 6 Ville Voutilainen 2019-04-17 09:23:50 UTC
Any chance of moving this warning out of -Wextra and re-considering adding it there for GCC 10?
Comment 7 Ville Voutilainen 2019-04-17 09:25:05 UTC
Innocent users are going to hit it: https://bugreports.qt.io/browse/QTBUG-75210
Comment 8 maic 2019-04-17 15:38:27 UTC
Indeed this will be hit even when the own code has no issue, but qt headers are included. See also https://github.com/bitcoin/bitcoin/issues/15822
Comment 9 Stephan Bergmann 2019-11-28 08:36:11 UTC
(In reply to Ville Voutilainen from comment #2)
> This is not just a Qt problem. I will write a proposal to undeprecate this
> deprecation for C++20 before the next committee meeting.

Can you give a link to that proposal?
Comment 10 Jonathan Wakely 2019-11-28 08:54:53 UTC
I don't think it has been written yet.
Comment 11 Ville Voutilainen 2019-11-28 09:56:52 UTC
(In reply to Jonathan Wakely from comment #10)
> I don't think it has been written yet.

Right; I decided against it, since the cats are out of the bag and shipping implementations voted with their feet, so Rule of Five is now the law of the land, as far as I care.
Comment 12 Nikita Kniazev 2021-02-26 00:13:24 UTC
Could GCC folks subscribed to this thread take a look on false-positive report (bug 92145) and not working suppression pragma (bug 94492) for this warning, please?
Comment 13 Jason Merrill 2023-12-19 20:48:29 UTC
So let's call this fixed.