Silence -Wunused-but-set-variable error with clang
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 4 Aug 2022 18:28:25 +0000 (14:28 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 21 Oct 2023 11:56:09 +0000 (07:56 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8655
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
(cherry picked from commit 2ea09241f07f1dfd4b6fd0f2f296a10142fda7d2)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11116
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/common/macros.h
src/plugins/ctf/common/metadata/parser.y

index ff7da410106a39d981556cd13d0905d2a2d662b8..c42cdf5a52f358d1e5c8d13a09689a99bbe8e73d 100644 (file)
                _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
index f75e577b42b18559afd01f96b6b917a8c5731ecf..b74497b034189b478cdd7792edd7760080d487f0 100644 (file)
 
 #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)
This page took 0.026043 seconds and 4 git commands to generate.