From e3e899ce2c68608f09259ad30969e54f045aadc1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 4 Aug 2022 14:28:25 -0400 Subject: [PATCH] Silence -Wunused-but-set-variable error with clang When building with clang-15, I get: CXX libctf_parser_la-parser.lo parser.cpp:2920:9: error: variable 'yynerrs' set but not used [-Werror,-Wunused-but-set-variable] int yynerrs; ^ This is because it warns for something like this: int n; n = 0; ++n; whereas previous versions do not. This is generated code, so there's not much more we can do other than silence the warning for the file. Change-Id: If2cffe9042b743ffe4b4b23f751216f67b58e5fa Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8655 Reviewed-by: Philippe Proulx (cherry picked from commit 2ea09241f07f1dfd4b6fd0f2f296a10142fda7d2) Reviewed-on: https://review.lttng.org/c/babeltrace/+/11116 CI-Build: Michael Jeanson Tested-by: jenkins --- src/common/macros.h | 11 +++++++++++ src/plugins/ctf/common/metadata/parser.y | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/common/macros.h b/src/common/macros.h index ff7da410..c42cdf5a 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -61,4 +61,15 @@ _ref; \ }) +#if defined __clang__ +# if __has_warning("-Wunused-but-set-variable") +# define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE \ + _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") +# endif +#endif + +#if !defined BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE +# define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE +#endif + #endif diff --git a/src/plugins/ctf/common/metadata/parser.y b/src/plugins/ctf/common/metadata/parser.y index f75e577b..b74497b0 100644 --- a/src/plugins/ctf/common/metadata/parser.y +++ b/src/plugins/ctf/common/metadata/parser.y @@ -46,6 +46,12 @@ #include "parser-wrap.h" +/* + * Avoid warning about "yynerrs" being unused, seen with bison 3.5.1 + clang 15 + * on Ubuntu 20.04. + */ +BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE + /* Join two lists, put "add" at the end of "head". */ static inline void _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head) -- 2.34.1