aboutsummaryrefslogtreecommitdiffstats
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-03-29 16:39:10 +0900
committerJunio C Hamano <gitster@pobox.com>2025-03-29 16:39:10 +0900
commitf76fe4ab067b9d6e530edf8205b5672ebad27bfc (patch)
tree7d8e5a823e75ee64c35b839fceedd9cbeb5074c5 /git-compat-util.h
parentb9b404fa1cdb43a54962188d883fafb5d2f9912d (diff)
parent16f5d967e2267ea37cd29d7aee21994921b6b98c (diff)
downloadgit-f76fe4ab067b9d6e530edf8205b5672ebad27bfc.tar.gz
Merge branch 'jk/use-wunreachable-code-for-devs'
Enable -Wunreachable-code for developer builds. * jk/use-wunreachable-code-for-devs: config.mak.dev: enable -Wunreachable-code git-compat-util: add NOT_CONSTANT macro and use it in atfork_prepare() run-command: use errno to check for sigfillset() error
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index e123288e8f..cf733b38ac 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1583,4 +1583,13 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)
((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))
#endif /* !__GNUC__ */
+/*
+ * Prevent an overly clever compiler from optimizing an expression
+ * out, triggering a false positive when building with the
+ * -Wunreachable-code option. false_but_the_compiler_does_not_know_it_
+ * is defined in a compilation unit separate from where the macro is
+ * used, initialized to 0, and never modified.
+ */
+#define NOT_CONSTANT(expr) ((expr) || false_but_the_compiler_does_not_know_it_)
+extern int false_but_the_compiler_does_not_know_it_;
#endif