[PATCH v3 09/10] clang: warn when the comma operator is used
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 27, 2025, 11:53 UTC
- Message-ID
- <6b6cd556465f21e43536706c88c49f8790a2dc5f.1743076383.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1889.v3.git.1743076383.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
When compiling Git using `clang`, the `-Wcomma` option can be used to warn about code using the comma operator (because it is typically unintentional and wants to use the semicolon instead).
Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- config.mak.dev | 4 ++++ meson.build | 1 + 2 files changed, 5 insertions(+)
diff --git a/config.mak.dev b/config.mak.dev index 0fd8cc4d355..31423638169 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -40,6 +40,10 @@ DEVELOPER_CFLAGS += -Wvla DEVELOPER_CFLAGS += -Wwrite-strings DEVELOPER_CFLAGS += -fno-common +ifneq ($(filter clang9,$(COMPILER_FEATURES)),) +DEVELOPER_CFLAGS += -Wcomma +endif + ifneq ($(filter clang4,$(COMPILER_FEATURES)),) DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare endif diff --git a/meson.build b/meson.build index efe2871c9db..fd8c05dec91 100644 --- a/meson.build +++ b/meson.build @@ -715,6 +715,7 @@ libgit_dependencies = [ ] # Makefile. if get_option('warning_level') in ['2','3', 'everything'] and compiler.get_argument_syntax() == 'gcc' foreach cflag : [ + '-Wcomma', '-Wdeclaration-after-statement', '-Wformat-security', '-Wold-style-definition',
-- gitgitgadget