Thread (2 messages) flat view 2 messages, 2 authors, 2024-08-29
STALE755d

[PATCH 9/6] git-compat-util: guard definition of MAYBE_UNUSED with __GNUC__

From: Junio C Hamano <hidden>
Date: 2024-08-29 18:27:42
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Just like we only define UNUSED macro when __GNUC__ is defined,
and fall back to an empty definition otherwise, we should do the
same for MAYBE_UNUSED.

Signed-off-by: Junio C Hamano <redacted>
---
 * Before I forget that we have discussed this, just as a
   documentation (read: this is not a patch to be applied).

   I think this only matters when a compiler satisfies all three
   traits:

   - does not define __GNUC__
   - does have its own __attribute__() macro
   - barfs on __attribute__((__unused__))

   Otherwise we will define __attribute__(x) away to empty to cause
   no harm.

   Since we have survived without complaints without such a guard
   for quite some time, it may be a sign that no compiler that knows
   __attribute__() that people ever tried to compile Git with barfs
   with __attribute__((__unused__)).  I dunno.

 git-compat-util.h | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/git-compat-util.h b/git-compat-util.h
index e4a306dd56..74ed581b5d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -673,7 +673,11 @@ static inline int git_has_dir_sep(const char *path)
  * would give a warning in a compilation where it is unused.  In such
  * a case, MAYBE_UNUSED is the appropriate annotation to use.
  */
+#ifdef __GNUC__
 #define MAYBE_UNUSED __attribute__((__unused__))
+#else
+#define MAYBE_UNUSED
+#endif
 
 #include "compat/bswap.h"
 
-- 
2.46.0-563-gaeb9b172ce
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help