aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-05-18 16:02:48 -0400
committerJason Merrill <jason@gcc.gnu.org>2018-05-18 16:02:48 -0400
commitb46b715d5b838d9869f89d3594ebf7d0b7cb374c (patch)
tree5684d331d1a9d9e995bb252f9febf8e86618a0a5 /gcc/cp/decl2.c
parentf07c22376848e9923aa8455d2c0a059d9d0e01d5 (diff)
downloadgcc-b46b715d5b838d9869f89d3594ebf7d0b7cb374c.zip
gcc-b46b715d5b838d9869f89d3594ebf7d0b7cb374c.tar.gz
gcc-b46b715d5b838d9869f89d3594ebf7d0b7cb374c.tar.bz2
PR c++/58407 - deprecated implicit copy ops.
gcc/c-family/ * c.opt (Wdeprecated-copy): New flag. gcc/cp/ * call.c (build_over_call): Warn about deprecated trivial fns. * class.c (classtype_has_user_copy_or_dtor): New. (type_build_ctor_call): Check TREE_DEPRECATED. (type_build_dtor_call): Likewise. * decl2.c (cp_warn_deprecated_use): Move from tree.c. Add checks. Return bool. Handle -Wdeprecated-copy. (mark_used): Use it. * decl.c (grokdeclarator): Remove redundant checks. * typeck2.c (build_functional_cast): Likewise. * method.c (lazily_declare_fn): Mark deprecated copy ops. * init.c (build_aggr_init): Only set TREE_USED if there are side-effects. libitm/ * beginend.cc (save): Disable -Werror=deprecated-copy. From-SVN: r260381
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r--gcc/cp/decl2.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 126356d..b6e8e07 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5173,6 +5173,55 @@ maybe_instantiate_decl (tree decl)
}
}
+/* Maybe warn if DECL is deprecated, subject to COMPLAIN. Returns whether or
+ not a warning was emitted. */
+
+bool
+cp_warn_deprecated_use (tree decl, tsubst_flags_t complain)
+{
+ if (!(complain & tf_warning) || !decl
+ || deprecated_state == DEPRECATED_SUPPRESS)
+ return false;
+
+ if (!TREE_DEPRECATED (decl))
+ {
+ /* Perhaps this is a deprecated typedef. */
+ if (TYPE_P (decl) && TYPE_NAME (decl))
+ decl = TYPE_NAME (decl);
+
+ if (!TREE_DEPRECATED (decl))
+ return false;
+ }
+
+ /* Don't warn within members of a deprecated type. */
+ if (TYPE_P (decl)
+ && currently_open_class (decl))
+ return false;
+
+ bool warned = false;
+ if (cxx_dialect >= cxx11
+ && DECL_P (decl)
+ && DECL_ARTIFICIAL (decl)
+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
+ && copy_fn_p (decl))
+ {
+ warned = warning (OPT_Wdeprecated_copy,
+ "implicitly-declared %qD is deprecated", decl);
+ if (warned)
+ {
+ 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);
+ }
+ }
+ else
+ warned = warn_deprecated_use (decl, NULL_TREE);
+
+ return warned;
+}
+
/* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
If DECL is a specialization or implicitly declared class member,
generate the actual definition. Return false if something goes
@@ -5237,9 +5286,7 @@ mark_used (tree decl, tsubst_flags_t complain)
return false;
}
- if (TREE_DEPRECATED (decl) && (complain & tf_warning)
- && deprecated_state != DEPRECATED_SUPPRESS)
- warn_deprecated_use (decl, NULL_TREE);
+ cp_warn_deprecated_use (decl, complain);
/* We can only check DECL_ODR_USED on variables or functions with
DECL_LANG_SPECIFIC set, and these are also the only decls that we