This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH for c++/79817 - attribute deprecated on namespace


On 8/20/19 9:03 PM, Marek Polacek wrote:

and in cp_parser_nested_name_specifier_opt we simply don't know if we're
dealing with a function decl.  Calling cp_warn_deprecated_use_scopes from
cp_parser_type_specifier resulted int duplicated diagnostics so that one
is out too.  So I did the following which doesn't seem too bad.


diff --git gcc/cp/decl.c gcc/cp/decl.c
index 08b7baa40e0..46ad0271f7b 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -10791,6 +10791,7 @@ grokdeclarator (const cp_declarator *declarator,
    cp_warn_deprecated_use (type);
    if (type && TREE_CODE (type) == TYPE_DECL)
      {
+      cp_warn_deprecated_use_scopes (DECL_CONTEXT (type));

CP_DECL_CONTEXT would be clearer, here and elsewhere.

    /* Do warn about using typedefs to a deprecated class.  */
diff --git gcc/cp/decl2.c gcc/cp/decl2.c
index a32108f9d16..d6f407d7aef 100644
--- gcc/cp/decl2.c
+++ gcc/cp/decl2.c
@@ -5407,6 +5407,23 @@ cp_warn_deprecated_use (tree decl, tsubst_flags_t complain)
    return warned;
  }
+/* Like above, but takes into account outer scopes. */
+
+void
+cp_warn_deprecated_use_scopes (tree ns)

Do we need to walk non-namespace scopes here? can we just bail if NS is not a namespace? if can legitimately not be a namespace, calling it NS is confusing :)

+{
+  while (ns
+	 && ns != error_mark_node
+	 && ns != global_namespace)
+    {
+      cp_warn_deprecated_use (ns);
+      if (TYPE_P (ns))
... and does this ever trigger?

+	ns = CP_TYPE_CONTEXT (ns);
+      else
+	ns = CP_DECL_CONTEXT (ns);
+    }
+}

I always worry about such recursive lookups. NAMESPACE_DECL has so many spare flags, could we take one to say 'is, or contained in, deprecated', and thus know whether we can bail early. And stop at the first deprecated one -- though not sure why someone would deprecate more than one namespace in a nest. thoughts?

otherwise looks good, with a good set of tests.

nathan

--
Nathan Sidwell


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]