public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: RFA (tree.c): PATCH to make warn_deprecated_use return bool
Date: Wed, 16 May 2018 02:34:00 -0000	[thread overview]
Message-ID: <CADzB+2=zOwhfW-4httHK2HWD4AAPWps0wb1SRFWRj7r30K1fnw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 407 bytes --]

The function "warning" returns bool to indicated whether or not any
diagnostic was actually emitted; warn_deprecated_use should as well.

It's also unnecessary to duplicate the warning code between the cases
of null or non-null "decl", since the actual warnings were the same.
The only thing that's different is whether we indicate the source
location of "decl".

Tested x86_64-pc-linux-gnu.  OK for trunk?

[-- Attachment #2: warn-depr-bool.diff --]
[-- Type: text/x-patch, Size: 3144 bytes --]

commit b49f292814693de97b218f6d8b32b20dd68fb8c8
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 15 17:41:19 2018 -0400

            * tree.c (warn_deprecated_use): Return bool.  Simplify logic.

diff --git a/gcc/tree.c b/gcc/tree.c
index 77a73b4495e..68165f4deed 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -12420,14 +12420,16 @@ typedef_variant_p (const_tree type)
   return is_typedef_decl (TYPE_NAME (type));
 }
 
-/* Warn about a use of an identifier which was marked deprecated.  */
-void
+/* Warn about a use of an identifier which was marked deprecated.  Returns
+   whether a warning was given.  */
+
+bool
 warn_deprecated_use (tree node, tree attr)
 {
   const char *msg;
 
   if (node == 0 || !warn_deprecated_decl)
-    return;
+    return false;
 
   if (!attr)
     {
@@ -12450,7 +12452,7 @@ warn_deprecated_use (tree node, tree attr)
   else
     msg = NULL;
 
-  bool w;
+  bool w = false;
   if (DECL_P (node))
     {
       if (msg)
@@ -12476,49 +12478,29 @@ warn_deprecated_use (tree node, tree attr)
 	    what = DECL_NAME (TYPE_NAME (node));
 	}
 
-      if (decl)
+      if (what)
 	{
-	  if (what)
-	    {
-	      if (msg)
-		w = warning (OPT_Wdeprecated_declarations,
-			     "%qE is deprecated: %s", what, msg);
-	      else
-		w = warning (OPT_Wdeprecated_declarations,
-			     "%qE is deprecated", what);
-	    }
+	  if (msg)
+	    w = warning (OPT_Wdeprecated_declarations,
+			 "%qE is deprecated: %s", what, msg);
 	  else
-	    {
-	      if (msg)
-		w = warning (OPT_Wdeprecated_declarations,
-			     "type is deprecated: %s", msg);
-	      else
-		w = warning (OPT_Wdeprecated_declarations,
-			     "type is deprecated");
-	    }
-	  if (w)
-	    inform (DECL_SOURCE_LOCATION (decl), "declared here");
+	    w = warning (OPT_Wdeprecated_declarations,
+			 "%qE is deprecated", what);
 	}
       else
 	{
-	  if (what)
-	    {
-	      if (msg)
-		warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
-			 what, msg);
-	      else
-		warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
-	    }
+	  if (msg)
+	    w = warning (OPT_Wdeprecated_declarations,
+			 "type is deprecated: %s", msg);
 	  else
-	    {
-	      if (msg)
-		warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
-			 msg);
-	      else
-		warning (OPT_Wdeprecated_declarations, "type is deprecated");
-	    }
+	    w = warning (OPT_Wdeprecated_declarations,
+			 "type is deprecated");
 	}
+      if (w && decl)
+	inform (DECL_SOURCE_LOCATION (decl), "declared here");
     }
+
+  return w;
 }
 
 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
diff --git a/gcc/tree.h b/gcc/tree.h
index 74a0d1881a6..ef8bff405fe 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4828,7 +4828,7 @@ extern tree tree_strip_sign_nop_conversions (tree);
 extern const_tree strip_invariant_refs (const_tree);
 extern tree lhd_gcc_personality (void);
 extern void assign_assembler_name_if_needed (tree);
-extern void warn_deprecated_use (tree, tree);
+extern bool warn_deprecated_use (tree, tree);
 extern void cache_integer_cst (tree);
 extern const char *combined_fn_name (combined_fn);
 

             reply	other threads:[~2018-05-16  1:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16  2:34 Jason Merrill [this message]
2018-05-16  9:42 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADzB+2=zOwhfW-4httHK2HWD4AAPWps0wb1SRFWRj7r30K1fnw@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).