Skip to content

Commit 54795d3

Browse files
jeffhostetlergitster
authored andcommitted
config.mak.dev: disable suggest braces error on old clang versions
Add the "-Wno-missing-braces" option when building with an old version of clang to suppress the "suggest braces around initialization" error in developer mode. For example, using an old version of clang gives the following errors (when in DEVELOPER=1 mode): $ make builtin/merge-file.o CC builtin/merge-file.o builtin/merge-file.c:29:23: error: suggest braces around initialization \ of subobject [-Werror,-Wmissing-braces] mmfile_t mmfs[3] = { 0 }; ^ {} builtin/merge-file.c:31:20: error: suggest braces around initialization \ of subobject [-Werror,-Wmissing-braces] xmparam_t xmp = { 0 }; ^ {} 2 errors generated. This example compiles without error/warning with updated versions of clang. Since this is an obsolete error, use the -Wno-missing-braces option to silence the warning when using an older compiler. This avoids the need to update the code to use "{{0}}" style initializations. Upstream clang version 8 has the problem. It was fixed in version 9. The version of clang distributed by Apple with XCode has its own unique set of version numbers. Apple clang version 11 has the problem. It was fixed in version 12. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0feb86 commit 54795d3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

config.mak.dev

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,31 @@ DEVELOPER_CFLAGS += -Wno-missing-braces
6969
endif
7070
endif
7171

72+
# Old versions of clang complain about initializaing a
73+
# struct-within-a-struct using just "{0}" rather than "{{0}}". This
74+
# error is considered a false-positive and not worth fixing, because
75+
# new clang versions do not, so just disable it.
76+
#
77+
# The "bug" was fixed in upstream clang 9.
78+
#
79+
# Complicating this is that versions of clang released by Apple have
80+
# their own version numbers (associated with the corresponding version
81+
# of XCode) unrelated to the official clang version numbers.
82+
#
83+
# The bug was fixed in Apple clang 12.
84+
#
85+
ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
86+
ifeq ($(uname_S),Darwin) # if we are on darwin
87+
ifeq ($(filter clang12,$(COMPILER_FEATURES)),) # if version < 12
88+
DEVELOPER_CFLAGS += -Wno-missing-braces
89+
endif
90+
else # not darwin
91+
ifeq ($(filter clang9,$(COMPILER_FEATURES)),) # if version < 9
92+
DEVELOPER_CFLAGS += -Wno-missing-braces
93+
endif
94+
endif
95+
endif
96+
7297
# https://bugzilla.redhat.com/show_bug.cgi?id=2075786
7398
ifneq ($(filter gcc12,$(COMPILER_FEATURES)),)
7499
DEVELOPER_CFLAGS += -Wno-error=stringop-overread

0 commit comments

Comments
 (0)