]> granicus.if.org Git - graphviz/commitdiff
cgraph: add an abstraction for squashing unused symbol warnings
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 22 May 2022 00:27:12 +0000 (17:27 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 25 Jun 2022 19:38:23 +0000 (12:38 -0700)
lib/cgraph/CMakeLists.txt
lib/cgraph/Makefile.am
lib/cgraph/cgraph.vcxproj
lib/cgraph/cgraph.vcxproj.filters
lib/cgraph/unused.h [new file with mode: 0644]

index 1b12c4b18906af46658faa274f8eeeaeade25dae..ab983da8b2deb98da29f5dc61f95094212c7c3e1 100644 (file)
@@ -23,6 +23,7 @@ add_library(cgraph SHARED
   stack.h
   strcasecmp.h
   unreachable.h
+  unused.h
 
   # Source files
   agerror.c
index c1265354cea87b19cedd16d1ecb6392d006807a3..31b608e8a48c030bca523bc4496988a3ac62d95e 100644 (file)
@@ -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
index 8431b5926eb6c9afe58dfeb1f6661102a6622395..b31228eac74e526351bf0c47edb57120dedbe197 100644 (file)
@@ -109,6 +109,7 @@ win_flex -oscan.c scan.l</Command>
     <ClInclude Include="stack.h" />
     <ClInclude Include="strcasecmp.h" />
     <ClInclude Include="unreachable.h" />
+    <ClInclude Include="unused.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="agerror.c" />
index 84c8c2aa19c8ee355373f49949d3525853468bc7..3238e92f380f0ded66c95608e6d00655a9eddf58 100644 (file)
@@ -51,6 +51,9 @@
     <ClInclude Include="unreachable.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="unused.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="agerror.c">
diff --git a/lib/cgraph/unused.h b/lib/cgraph/unused.h
new file mode 100644 (file)
index 0000000..0b29a08
--- /dev/null
@@ -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