From: Matthew Fernandez Date: Sun, 22 May 2022 00:27:12 +0000 (-0700) Subject: cgraph: add an abstraction for squashing unused symbol warnings X-Git-Tag: 5.0.0~15^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e391f114f6dec532acc637a0484d72642bbffbd0;p=graphviz cgraph: add an abstraction for squashing unused symbol warnings --- diff --git a/lib/cgraph/CMakeLists.txt b/lib/cgraph/CMakeLists.txt index 1b12c4b18..ab983da8b 100644 --- a/lib/cgraph/CMakeLists.txt +++ b/lib/cgraph/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(cgraph SHARED stack.h strcasecmp.h unreachable.h + unused.h # Source files agerror.c diff --git a/lib/cgraph/Makefile.am b/lib/cgraph/Makefile.am index c1265354c..31b608e8a 100644 --- a/lib/cgraph/Makefile.am +++ b/lib/cgraph/Makefile.am @@ -10,7 +10,7 @@ endif pkginclude_HEADERS = cgraph.h noinst_HEADERS = agxbuf.h alloc.h bitarray.h cghdr.h exit.h itos.h likely.h \ - prisize_t.h stack.h strcasecmp.h unreachable.h + prisize_t.h stack.h strcasecmp.h unreachable.h unused.h noinst_LTLIBRARIES = libcgraph_C.la lib_LTLIBRARIES = libcgraph.la pkgconfig_DATA = libcgraph.pc diff --git a/lib/cgraph/cgraph.vcxproj b/lib/cgraph/cgraph.vcxproj index 8431b5926..b31228eac 100644 --- a/lib/cgraph/cgraph.vcxproj +++ b/lib/cgraph/cgraph.vcxproj @@ -109,6 +109,7 @@ win_flex -oscan.c scan.l + diff --git a/lib/cgraph/cgraph.vcxproj.filters b/lib/cgraph/cgraph.vcxproj.filters index 84c8c2aa1..3238e92f3 100644 --- a/lib/cgraph/cgraph.vcxproj.filters +++ b/lib/cgraph/cgraph.vcxproj.filters @@ -51,6 +51,9 @@ Header Files + + Header Files + diff --git a/lib/cgraph/unused.h b/lib/cgraph/unused.h new file mode 100644 index 000000000..0b29a08f4 --- /dev/null +++ b/lib/cgraph/unused.h @@ -0,0 +1,26 @@ +/// \file +/// \brief abstraction for squashing compiler warnings for unused symbols + +#pragma once + +/// squash an unused variable/function warning in C +/// +/// e.g. +/// +/// static UNUSED void my_uncalled_function(void) { } +/// static UNUSED int my_unused_variable; +/// +/// Use this sparingly, as the MSVC version applies to everything in both the +/// current and next line, so can end up accidentally masking genuine problems. +/// Only use this in C code. In C++, use `[[maybe_unused]]`. +#ifdef __GNUC__ // Clang and GCC +#define UNUSED __attribute__((unused)) +#elif defined(_MSC_VER) // MSVC +#define UNUSED \ + __pragma(warning(suppress : 4100 /* unreferenced formal parameter */ \ + 4101 /* unreferenced local variable */ \ + 4505 /* unreferenced local function */ \ + )) +#else +#define UNUSED /* nothing */ +#endif