public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] include: Add macro to ignore -Wunused-but-set-variable
@ 2022-09-22 11:28 Tsukasa OI
  0 siblings, 0 replies; only message in thread
From: Tsukasa OI @ 2022-09-22 11:28 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d9fa9b7c3306008ee97140a3aafc56999d8cd2cd

commit d9fa9b7c3306008ee97140a3aafc56999d8cd2cd
Author: Tsukasa OI <research_trasio@irq.a4lg.com>
Date:   Mon Sep 12 08:04:40 2022 +0000

    include: Add macro to ignore -Wunused-but-set-variable
    
    "-Wunused-but-set-variable" warning option can be helpful to track variables
    that are written but not read thereafter.  But it can be harmful if some of
    the code is auto-generated and we have no ways to deal with it.
    
    The particular example is Bison-generated code.
    
    The new DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE macro can be helpful on
    such cases. A typical use of this macro is to place this macro before the
    end of user prologues on Bison (.y) files.
    
    include/ChangeLog:
    
        * diagnostics.h (DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE): New.

Diff:
---
 include/diagnostics.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/diagnostics.h b/include/diagnostics.h
index dbe6288d3d6..4161dff6abc 100644
--- a/include/diagnostics.h
+++ b/include/diagnostics.h
@@ -68,6 +68,11 @@
    DIAGNOSTIC_IGNORE ("-Wuser-defined-warnings")
 # endif
 
+# if __has_warning ("-Wunused-but-set-variable")
+#  define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
+   DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
+# endif
+
 # define DIAGNOSTIC_ERROR_SWITCH \
   DIAGNOSTIC_ERROR ("-Wswitch")
 
@@ -89,6 +94,11 @@
 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
   DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
 
+# if __GNUC__ >= 5
+#  define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE \
+   DIAGNOSTIC_IGNORE ("-Wunused-but-set-variable")
+# endif
+
 /* GCC 4.8's "diagnostic push/pop" seems broken when using this, -Wswitch
    remains enabled at the error level even after a pop.  Therefore, don't
    use it for GCC < 5.  */
@@ -130,6 +140,10 @@
 # define DIAGNOSTIC_IGNORE_USER_DEFINED_WARNINGS
 #endif
 
+#ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
+# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE
+#endif
+
 #ifndef DIAGNOSTIC_ERROR_SWITCH
 # define DIAGNOSTIC_ERROR_SWITCH
 #endif

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-22 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 11:28 [binutils-gdb] include: Add macro to ignore -Wunused-but-set-variable Tsukasa OI

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).