suppress a particular warning for an individual function; useful for non-gcc
Microsoft and other non-GNU compilers don't recognize gcc tricks like /*NOTREACHED*/ to suppress individual warnings. clang recognizes most of them because it tries to be gcc-compatible. Because of that, a lot of potentially useful warnings have had to be completely suppressed in the past in all source files when using the non-gcc compatible compilers. Now that the code is C99, take advantage of a way to suppress warnings for individual functions, a big step up from suppressing the warnings altogether. Unfortunately, it does require a bit of ugliness caused by the insertion of some macros in a few spots, but I'm not aware of a cleaner alternative that still allows warnings to be enabled in general, while suppressing a warning for known white-listed instances. Prior to the warning-tiggering function, place whichever one of the following is needed to suppress the warning being encountered: DISABLE_WARNING_UNREACHABLE_CODE DISABLE_WARNING_CONDEXPR_IS_CONSTANT After the warning-triggering function, place this: RESTORE_WARNINGS Under the hood, the compiler-appropriate warning-disabling mechanics involve the use of C99 _Pragma, which can be used in macros. For unrecognized or inappropriate compilers, or if DISABLE_WARNING_PRAGMAS is defined, the macros expand to nothing.
This commit is contained in:
@@ -183,6 +183,8 @@ int yoffset, xoffset;
|
||||
char bmpname[128];
|
||||
FILE *fp;
|
||||
|
||||
DISABLE_WARNING_UNREACHABLE_CODE
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@@ -268,6 +270,8 @@ main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
RESTORE_WARNINGS
|
||||
|
||||
static void
|
||||
build_bmfh(BITMAPFILEHEADER* pbmfh)
|
||||
{
|
||||
|
||||
@@ -644,6 +644,8 @@ extern void monst_globals_init(void);
|
||||
extern void objects_globals_init(void);
|
||||
#endif
|
||||
|
||||
DISABLE_WARNING_UNREACHABLE_CODE
|
||||
|
||||
int
|
||||
main(int argc UNUSED, char *argv[] UNUSED)
|
||||
{
|
||||
@@ -694,6 +696,8 @@ main(int argc UNUSED, char *argv[] UNUSED)
|
||||
return 0;
|
||||
}
|
||||
|
||||
RESTORE_WARNINGS
|
||||
|
||||
#endif /* TILETEXT */
|
||||
|
||||
struct {
|
||||
|
||||
Reference in New Issue
Block a user