From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 3C4303858D28; Mon, 17 Oct 2022 12:38:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C4303858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666010324; bh=PQD48QolWr58mkdvjRydjjOM5TzHwNMD76cuM1UyHHg=; h=From:To:Subject:Date:From; b=CuxH7Z9lT37ggCmI/LZBYwTgCNvoaf1fvwy9t1D/rS9UoJ7+Hn38OlYNsyAuy7LxV K737FYSYDRpVvkun6IC+F5p4plQVFjI40rp1TfDAgRxwAg+dRB0Zb2dvWRY4ajbkOu 0LkZCETKxyiK3+0eD843ytWSbAHPbFgFFK6PTck8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 95a20247e8caf4b2dfe3ccc587fe59d53d0e5bb6 X-Git-Newrev: e57f7fa070e16683c0e1ddd0d1307d243fad990d Message-Id: <20221017123844.3C4303858D28@sourceware.org> Date: Mon, 17 Oct 2022 12:38:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De57f7fa070e1= 6683c0e1ddd0d1307d243fad990d commit e57f7fa070e16683c0e1ddd0d1307d243fad990d Author: Simon Marchi Date: Wed Oct 12 13:32:56 2022 -0400 gdb: silence unused-but-set-variable warning about yynerrs in cp-name-p= arser.y =20 When building with clang 15 on Ubuntu 20.04, I get: =20 CXX cp-name-parser.o cp-name-parser.c.tmp:1777:9: error: variable 'cpnameyynerrs' set bu= t not used [-Werror,-Wunused-but-set-variable] int yynerrs; ^ /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:58:18: note: expanded= from macro 'yynerrs' #define yynerrs GDB_YY_REMAP (yynerrs) ^ /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:40:29: note: expanded= from macro 'GDB_YY_REMAP' #define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YY= SYM) ^ /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:39:39: note: expanded= from macro 'GDB_YY_REMAP_1' #define GDB_YY_REMAP_1(PREFIX, YYSYM) GDB_YY_REMAP_2 (PREFIX, YYSYM) ^ /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:38:39: note: expanded= from macro 'GDB_YY_REMAP_2' #define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM ^ :45:1: note: expanded from here cpnameyynerrs ^ =20 This is because clang 15 warns for something like this: =20 int n; n =3D 0; ++n; =20 whereas previous versions do not. =20 yynerrs is defined in yyparse and is there for actions to use. Since the actions in cp-name-parser.y don't use it, we get a warning. We see this problem on this particular .y file because it uses `%pure-parser` [1], which makes yynerrs a local rather than a global. =20 I initially fixed this by using DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE (like in commit f7aa1a5acc5 ("gold: Suppress "unused" variable warning on Clang")), but then I realized we could suppress the warning in a more fine-grained way using this in a rule: =20 (void) yynerrs; =20 [1] https://www.gnu.org/software/bison/manual/html_node/Error-Reporting= -Function.html =20 Change-Id: I6cae7a4207c19fe1b719e2ac19be69122ebe3af1 Diff: --- gdb/cp-name-parser.y | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 34c691ddabb..1108c787b7e 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -346,7 +346,12 @@ static void yyerror (cpname_state *, const char *); %% =20 result : start - { state->global_result =3D $1; } + { + state->global_result =3D $1; + + /* Avoid warning about "yynerrs" being unused. */ + (void) yynerrs; + } ; =20 start : type