| 1 |
/// \file |
| 2 |
/// \brief abstraction for squashing compiler warnings for unused symbols |
| 3 |
/// \ingroup cgraph_utils |
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
/// squash an unused variable/function warning in C |
| 8 |
/// |
| 9 |
/// e.g. |
| 10 |
/// |
| 11 |
/// static UNUSED void my_uncalled_function(void) { } |
| 12 |
/// static UNUSED int my_unused_variable; |
| 13 |
/// |
| 14 |
/// Use this sparingly, as the MSVC version applies to everything in both the |
| 15 |
/// current and next line, so can end up accidentally masking genuine problems. |
| 16 |
#ifdef __GNUC__ // Clang and GCC |
| 17 |
#define UNUSED __attribute__((unused)) |
| 18 |
#elif defined(_MSC_VER) // MSVC |
| 19 |
#define UNUSED \ |
| 20 |
__pragma(warning(suppress : 4100 /* unreferenced formal parameter */ \ |
| 21 |
4101 /* unreferenced local variable */ \ |
| 22 |
4505 /* unreferenced local function */ \ |
| 23 |
)) |
| 24 |
#else |
| 25 |
#define UNUSED /* nothing */ |
| 26 |
#endif |
| 27 |
|
| 28 |
/// annotate that a function’s return value should not be ignored |
| 29 |
/// |
| 30 |
/// e.g. |
| 31 |
/// |
| 32 |
/// WUR int foo(void) { |
| 33 |
/// return 42; |
| 34 |
/// } |
| 35 |
/// void bar(void) { |
| 36 |
/// foo(); // ← this line will generate a compiler warning |
| 37 |
/// } |
| 38 |
#ifdef __GNUC__ // Clang and GCC |
| 39 |
#define WUR __attribute__((warn_unused_result)) |
| 40 |
#elif defined(_MSC_VER) // MSVC |
| 41 |
#define WUR _Check_return_ |
| 42 |
#else |
| 43 |
#define WUR /* nothing */ |
| 44 |
#endif |