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:
nhmall
2021-02-01 12:54:19 -05:00
parent 7445435a36
commit a6631e3bb0
12 changed files with 125 additions and 4 deletions

View File

@@ -521,7 +521,7 @@ CSOURCES = $(HACKCSRC) $(SYSCSRC) $(WINCSRC) $(CHAINSRC) $(GENCSRC)
HACKINCL = align.h artifact.h artilist.h attrib.h botl.h \
color.h config.h config1.h context.h coord.h decl.h \
display.h dlb.h dungeon.h engrave.h extern.h flag.h fnamesiz.h \
func_tab.h global.h hack.h lint.h mextra.h mfndpos.h \
func_tab.h global.h warnings.h hack.h lint.h mextra.h mfndpos.h \
micro.h mkroom.h \
monattk.h mondata.h monflag.h monst.h monsym.h obj.h objclass.h \
optlist.h patchlevel.h pcconf.h permonst.h prop.h rect.h \
@@ -790,9 +790,9 @@ depend: ../sys/unix/depend.awk \
# config.h timestamp
$(CONFIG_H): ../include/config.h ../include/config1.h ../include/patchlevel.h \
../include/tradstdc.h ../include/global.h ../include/coord.h \
../include/vmsconf.h ../include/system.h ../include/nhlua.h \
../include/unixconf.h ../include/pcconf.h ../include/micro.h \
../include/tradstdc.h ../include/global.h ../include/warnings.h \
../include/coord.h ../include/vmsconf.h ../include/system.h \
../include/nhlua.h ../include/unixconf.h ../include/pcconf.h \
../include/ntconf.h ../include/fnamesiz.h
touch $(CONFIG_H)
# hack.h timestamp