From: nhmall Date: Wed, 3 Feb 2021 18:18:43 +0000 (-0500) Subject: clear a number of Qt build warnings on linux related to compiler flags X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b21a170fb37293f4a66d07e99b6bdfaa886ae45;p=nethack clear a number of Qt build warnings on linux related to compiler flags option ‘-Wimplicit’ is valid for C/ObjC but not for C++ option ‘-Wimplicit-function-declaration’ is valid for C/ObjC but not for C++ option ‘-Wimplicit-int’ is valid for C/ObjC but not for C++ option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ option ‘-Wmissing-parameter-type’ is valid for C/ObjC but not for C++ option ‘-Wold-style-definition’ is valid for C/ObjC but not for C++ option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ --- diff --git a/include/warnings.h b/include/warnings.h index f0cab3de4..a1809a9a9 100644 --- a/include/warnings.h +++ b/include/warnings.h @@ -31,11 +31,13 @@ #define ACTIVATE_WARNING_PRAGMAS #endif #endif -#if defined(__clang__) && defined(__cplusplus) +#if defined(__GNUC__) || defined(__clang__) +#if defined(__cplusplus) #ifndef ACTIVATE_WARNING_PRAGMAS #define ACTIVATE_WARNING_PRAGMAS #endif -#endif +#endif /* __cplusplus */ +#endif /* __GNUC__ || __clang__ */ #ifdef ACTIVATE_WARNING_PRAGMAS #if defined(__clang__) @@ -89,6 +91,7 @@ #endif /* DISABLE_WARNING_PRAGMAS */ #if !defined(STDC_Pragma_AVAILABLE) +#error not good #define DISABLE_WARNING_UNREACHABLE_CODE #define DISABLE_WARNING_FORMAT_NONLITERAL #define DISABLE_WARNING_CONDEXPR_IS_CONSTANT diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index 415b404c2..3c47316fc 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -176,7 +176,7 @@ SYSOBJ = $(TARGETPFX)ioctl.o $(TARGETPFX)unixmain.o $(TARGETPFX)unixtty.o \ # The Qt and Be window systems are written in C++, while the rest of # NetHack is standard C. If using Qt, uncomment the LINK line here to get # the C++ libraries linked in. -CXXFLAGS = $(CFLAGS) -I. -I$(QTDIR)/include $(QTCXXFLAGS) +CXXFLAGS = -I. -I$(QTDIR)/include $(QTCXXFLAGS) CXX ?= g++ MOC ?= moc #LINK=g++ diff --git a/sys/unix/hints/include/compiler.2020 b/sys/unix/hints/include/compiler.2020 index 07fca15c3..3205c09e2 100755 --- a/sys/unix/hints/include/compiler.2020 +++ b/sys/unix/hints/include/compiler.2020 @@ -27,32 +27,35 @@ endif #CXX=clang++ -std=gnu++11 CFLAGS=$(CCFLAGS) -I../include -DNOTPARMDECL - -ifndef WANT_WIN_QT -ifndef WANT_LIBNH -# these are normally used when compiling nethack's core -# but -ansi forces -std=c90 for C or -std=c++98 for C++; -# win/Qt/qt_*.cpp compiled with C++98 semantics trigger -#In file included from .../qt5/include/QtCore/qglobal.h:105: -#.../qt5/include/QtCore/qcompilerdetection.h:561:6: -# error Qt requires a C++11 compiler and yours does not seem to be that. -# so we suppress -ansi when the build includes Qt -#CFLAGS+=-ansi -Wno-long-long -#CFLAGS+=-std=c99 -# -#LIBNH's winshim requires C99 for the way it is currently coded -endif -endif - -CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit \ +CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \ -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings CFLAGS+=-pedantic +CFLAGS+=-Wmissing-declarations +CFLAGS+=-Wformat-nonliteral CFLAGS+=-DGCC_WARN +# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so +# # leave it out by default. +# #CFLAGS+=-Wunreachable-code +# # +# +# the following are not allowed in C++ +CFLAGS+=-Wimplicit CFLAGS+=-Wimplicit-function-declaration CFLAGS+=-Wimplicit-int -CFLAGS+=-Wmissing-declarations CFLAGS+=-Wmissing-prototypes -CFLAGS+=-Wformat-nonliteral +CFLAGS+=-Wold-style-definition +CFLAGS+=-Wstrict-prototypes + +ifdef WANT_WIN_QT +QTCXXFLAGS = -g -I../include -DNOTPARMDECL +QTCXXFLAGS+=-Wall -Wextra -Wno-missing-field-initializers \ + -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings +QTCXXFLAGS+=-pedantic +QTCXXFLAGS+=-Wmissing-declarations +QTCXXFLAGS+=-Wformat-nonliteral +QTCXXFLAGS+=-DGCC_WARN +endif + ifeq "$(CCISCLANG)" "" #gcc-specific here CFLAGS+=-Wmissing-parameter-type @@ -62,15 +65,20 @@ ifeq "$(GCCGTEQ9)" "1" # flags present in gcc version greater than or equal to 9 can go here #CFLAGS+=-Wno-format-overflow endif #gcc version greater than or equal to 9 + +ifdef WANT_WIN_QT +# get the version of g++ +GPPGTEQ9 := $(shell expr `$(CXX) -dumpversion | cut -f1 -d.` \>= 9) +ifeq "$(GPPGTEQ9)" "1" +#QTCXXFLAGS+=-Wno-format-overflow +endif #g++ version greater than or equal to 9 +#QTCXXFLAGS+= -Wno-format-truncation +QTCXXFLAGS+= -Wno-deprecated-copy +endif #WANT_WIN_QT + else # clang # clang-specific here endif # clang -# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so -# leave it out by default. -#CFLAGS+=-Wunreachable-code -# -CFLAGS+=-Wold-style-definition -CFLAGS+=-Wstrict-prototypes #end of compiler.2020 #------------------------------------------------------------------------------