diff options
author | Jason Merrill <jason@redhat.com> | 2018-12-06 16:17:08 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-12-06 16:17:08 -0500 |
commit | 5c8b3702e36a8792fa297f6b2b2cc865e08bb1b7 (patch) | |
tree | 6b80e5d185cdf98f73f8ceefb770c17019adbbe1 /gcc/cp | |
parent | 6e00bd6eb238f106101e32ce5c76b4b3ab8e26cc (diff) | |
download | gcc-5c8b3702e36a8792fa297f6b2b2cc865e08bb1b7.zip gcc-5c8b3702e36a8792fa297f6b2b2cc865e08bb1b7.tar.gz gcc-5c8b3702e36a8792fa297f6b2b2cc865e08bb1b7.tar.bz2 |
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.
From-SVN: r266867
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/class.c | 2 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 25 | ||||
-rw-r--r-- | gcc/cp/method.c | 2 |
5 files changed, 27 insertions, 13 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1a3e73e..601ca78a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2018-12-06 Jason Merrill <jason@redhat.com> + + PR c++/88136 - -Wdeprecated-copy false positives + * 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. + 2018-12-06 Marek Polacek <polacek@redhat.com> PR c++/88373 - wrong parse error with ~. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 5726151..9c175f8 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5233,7 +5233,7 @@ classtype_has_non_deleted_move_ctor (tree t) operator, or destructor, returns that function. Otherwise, null. */ tree -classtype_has_user_copy_or_dtor (tree t) +classtype_has_depr_implicit_copy (tree t) { if (!CLASSTYPE_LAZY_COPY_CTOR (t)) for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 636e53a..3645965 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6273,7 +6273,7 @@ extern bool type_has_constexpr_default_constructor (tree); extern bool type_has_virtual_destructor (tree); extern bool classtype_has_move_assign_or_move_ctor_p (tree, bool user_declared); extern bool classtype_has_non_deleted_move_ctor (tree); -extern tree classtype_has_user_copy_or_dtor (tree); +extern tree classtype_has_depr_implicit_copy (tree); extern bool type_build_ctor_call (tree); extern bool type_build_dtor_call (tree); extern void explain_non_literal_class (tree); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f996a27..15b0393 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -5298,18 +5298,23 @@ cp_warn_deprecated_use (tree decl, tsubst_flags_t complain) && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) && copy_fn_p (decl)) { - auto_diagnostic_group d; - /* Don't warn about system library classes (c++/86342). */ - if (!DECL_IN_SYSTEM_HEADER (decl)) - warned = warning (OPT_Wdeprecated_copy, - "implicitly-declared %qD is deprecated", decl); - if (warned) + if (warn_deprecated_copy + /* Don't warn about system library classes (c++/86342). */ + && (!DECL_IN_SYSTEM_HEADER (decl) + || global_dc->dc_warn_system_headers)) { + auto_diagnostic_group d; tree ctx = DECL_CONTEXT (decl); - tree other = classtype_has_user_copy_or_dtor (ctx); - inform (DECL_SOURCE_LOCATION (other), - "because %qT has user-provided %qD", - ctx, other); + tree other = classtype_has_depr_implicit_copy (ctx); + int opt = (DECL_DESTRUCTOR_P (other) + ? OPT_Wdeprecated_copy_dtor + : OPT_Wdeprecated_copy); + warned = warning (opt, "implicitly-declared %qD is deprecated", + decl); + if (warned) + inform (DECL_SOURCE_LOCATION (other), + "because %qT has user-provided %qD", + ctx, other); } } else diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 936dad4..fd023e2 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -2380,7 +2380,7 @@ lazily_declare_fn (special_function_kind sfk, tree type) { if (classtype_has_move_assign_or_move_ctor_p (type, true)) DECL_DELETED_FN (fn) = true; - else if (classtype_has_user_copy_or_dtor (type)) + else if (classtype_has_depr_implicit_copy (type)) /* The implicit definition of a copy constructor as defaulted is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor. The implicit definition of a copy |