2018-04-14 21:19:45 +02:00
|
|
|
ifeq ($(filter no-error,$(DEVOPTS)),)
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Werror
|
2018-04-14 21:19:45 +02:00
|
|
|
endif
|
2018-07-24 21:26:43 +02:00
|
|
|
ifneq ($(filter pedantic,$(DEVOPTS)),)
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -pedantic
|
2018-07-24 21:26:43 +02:00
|
|
|
# don't warn for each N_ use
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
|
|
|
|
endif
|
|
|
|
DEVELOPER_CFLAGS += -Wall
|
|
|
|
DEVELOPER_CFLAGS += -Wdeclaration-after-statement
|
|
|
|
DEVELOPER_CFLAGS += -Wformat-security
|
|
|
|
DEVELOPER_CFLAGS += -Wold-style-definition
|
|
|
|
DEVELOPER_CFLAGS += -Woverflow
|
|
|
|
DEVELOPER_CFLAGS += -Wpointer-arith
|
|
|
|
DEVELOPER_CFLAGS += -Wstrict-prototypes
|
|
|
|
DEVELOPER_CFLAGS += -Wunused
|
|
|
|
DEVELOPER_CFLAGS += -Wvla
|
config.mak.dev: build with -fno-common
It's an easy mistake to define a variable in a header with "int x;" when
you really meant to only declare the variable as "extern int x;"
instead. Clang and gcc will both allow this when building with
"-fcommon"; they put these "tentative definitions" in a common block
which the linker is able to resolve.
This is the default in clang and was the default in gcc until gcc-10,
since it helps some legacy code. However, we would prefer not to rely on
this because:
- using "extern" makes the intent more clear (so it's a style issue,
but it's one the compiler can help us catch)
- according to the gcc manpage, it may yield a speed and code size
penalty
So let's build explicitly with -fno-common when the DEVELOPER knob is
set, which will let developers using clang and older versions of gcc
notice these problems.
I didn't bother making this conditional on a particular version of gcc.
As far as I know, this option has been available forever in both gcc and
clang, so old versions don't need to avoid it. And we already expect gcc
and clang options throughout config.mak.dev, so it's unlikely anybody
setting the DEVELOPER knob is using anything else. It's a noop on
gcc-10, of course, but it's not worth trying to exclude it there.
Note that there's nothing to fix in the code; we already don't have any
issues here. But if you want to test the patch, you can add a bare "int
x;" into cache.h, which will cause the link step to fail.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-15 21:30:29 +02:00
|
|
|
DEVELOPER_CFLAGS += -fno-common
|
2018-04-14 21:19:44 +02:00
|
|
|
|
|
|
|
ifndef COMPILER_FEATURES
|
|
|
|
COMPILER_FEATURES := $(shell ./detect-compiler $(CC))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare
|
2018-04-14 21:19:44 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Wextra
|
2018-04-14 21:19:44 +02:00
|
|
|
# if a function is public, there should be a prototype and the right
|
|
|
|
# header file should be included. If not, it should be static.
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Wmissing-prototypes
|
2018-04-14 21:19:46 +02:00
|
|
|
ifeq ($(filter extra-all,$(DEVOPTS)),)
|
2018-04-14 21:19:44 +02:00
|
|
|
# These are disabled because we have these all over the place.
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Wno-empty-body
|
|
|
|
DEVELOPER_CFLAGS += -Wno-missing-field-initializers
|
|
|
|
DEVELOPER_CFLAGS += -Wno-sign-compare
|
|
|
|
DEVELOPER_CFLAGS += -Wno-unused-parameter
|
2018-04-14 21:19:44 +02:00
|
|
|
endif
|
2018-04-14 21:19:46 +02:00
|
|
|
endif
|
2018-04-14 21:19:44 +02:00
|
|
|
|
|
|
|
# uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
|
|
|
|
# not worth fixing since newer compilers correctly stop complaining
|
|
|
|
ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
|
|
|
|
ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
|
2019-02-22 15:41:27 +01:00
|
|
|
DEVELOPER_CFLAGS += -Wno-uninitialized
|
2018-04-14 21:19:44 +02:00
|
|
|
endif
|
|
|
|
endif
|