From f7db9305aa8642cb5145bba6f8948400c52396af Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 20 Sep 2018 10:38:08 +0200 Subject: [PATCH] BUILD: build with -Wextra and sort out certain warnings We're not far from being able to build with -Wextra -Werror. The following warnings had to be disabled to enable a clean build at -Wextra on x86_64 using gcc 4.7, 5.5, 6.4 and 7.3 : sign-compare, unused-parameter, old-style-declaration, ignored-qualifiers, clobbered, missing-field-initializers, implicit-fallthrough The following extra warnings could be added without side effects : type-limits, shift-negative-value, shift-overflow=2 duplicated-cond, null-dereference As a result, -Wextra was enabled by default, hoping it will help catch issues over the long term. If new undesired warnings pop up, it's easy to disable them using the nowarn call. --- Makefile | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4b5cc4072..382f944f3 100644 --- a/Makefile +++ b/Makefile @@ -153,8 +153,19 @@ SPEC_CFLAGS += $(call cc-opt,-fwrapv) SPEC_CFLAGS += $(call cc-opt,-fno-strict-overflow) SPEC_CFLAGS += $(call cc-nowarn,format-truncation) SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member) -SPEC_CFLAGS += $(call cc-nowarn,null-dereference) SPEC_CFLAGS += $(call cc-nowarn,unused-label) +SPEC_CFLAGS += $(call cc-nowarn,sign-compare) +SPEC_CFLAGS += $(call cc-nowarn,unused-parameter) +SPEC_CFLAGS += $(call cc-nowarn,old-style-declaration) +SPEC_CFLAGS += $(call cc-nowarn,ignored-qualifiers) +SPEC_CFLAGS += $(call cc-nowarn,clobbered) +SPEC_CFLAGS += $(call cc-nowarn,missing-field-initializers) +SPEC_CFLAGS += $(call cc-nowarn,implicit-fallthrough) +SPEC_CFLAGS += $(call cc-opt,-Wtype-limits) +SPEC_CFLAGS += $(call cc-opt,-Wshift-negative-value) +SPEC_CFLAGS += $(call cc-opt,-Wshift-overflow=2) +SPEC_CFLAGS += $(call cc-opt,-Wduplicated-cond) +SPEC_CFLAGS += $(call cc-opt,-Wnull-dereference) #### Memory usage tuning # If small memory footprint is required, you can reduce the buffer size. There @@ -806,7 +817,7 @@ EBTREE_DIR := ebtree #### Global compile options VERBOSE_CFLAGS = $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE) -COPTS = -Iinclude -I$(EBTREE_DIR) -Wall +COPTS = -Iinclude -I$(EBTREE_DIR) -Wall -Wextra COPTS += $(CFLAGS) $(TARGET_CFLAGS) $(SMALL_OPTS) $(DEFINE) $(SILENT_DEFINE) COPTS += $(DEBUG) $(OPTIONS_CFLAGS) $(ADDINC)