3 ms·
> This works. But both gcc and clang warn about the enum being anonymous... even though that's exactly what I wanted to do. And this cannot be silenced with #pr
by wahern 1y ago
> This works. But both gcc and clang warn about the enum being anonymous... even though that's exactly what I wanted to do. And this cannot be silenced with #pragma since it's a macro, so the warning occurs at the location where the macro is invoked.
You can use _Pragma instead of #pragma. E.g.
#define C(x) ( \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wvisibility\"") \
(x) + 0*sizeof(void (*)(enum { tmp = (int)(x) })) \
_Pragma("clang diagnostic pop") \
)
EDIT: Alas, GCC is a little pickier about where _Pragma is allowed so you may need to use a statement expression. Also, it seems GCC 14 doesn't have a -W switch that will disable the anonymous enum warning.