From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7896) id F39C43858009; Thu, 22 Sep 2022 11:28:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F39C43858009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tsukasa OI To: bfd-cvs@sourceware.org Subject: [binutils-gdb] include: Add macro to ignore -Wunused-but-set-variable X-Act-Checkin: binutils-gdb X-Git-Author: Tsukasa OI X-Git-Refname: refs/heads/master X-Git-Oldrev: c59ea02cc3cbc89cde1fcb72e4267b73cdaf7f55 X-Git-Newrev: d9fa9b7c3306008ee97140a3aafc56999d8cd2cd Message-Id: <20220922112859.F39C43858009@sourceware.org> Date: Thu, 22 Sep 2022 11:28:59 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2022 11:29:00 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd9fa9b7c3306= 008ee97140a3aafc56999d8cd2cd commit d9fa9b7c3306008ee97140a3aafc56999d8cd2cd Author: Tsukasa OI Date: Mon Sep 12 08:04:40 2022 +0000 include: Add macro to ignore -Wunused-but-set-variable =20 "-Wunused-but-set-variable" warning option can be helpful to track vari= ables that are written but not read thereafter. But it can be harmful if som= e of the code is auto-generated and we have no ways to deal with it. =20 The particular example is Bison-generated code. =20 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 t= he end of user prologues on Bison (.y) files. =20 include/ChangeLog: =20 * 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 =20 +# 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") =20 @@ -89,6 +94,11 @@ # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") =20 +# if __GNUC__ >=3D 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 =20 +#ifndef DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE +# define DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE +#endif + #ifndef DIAGNOSTIC_ERROR_SWITCH # define DIAGNOSTIC_ERROR_SWITCH #endif