From 5cf88fd8b059235b21ee2f72b17bf1f421a9c4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 25 Aug 2022 19:09:48 +0200 Subject: git-compat-util.h: use "UNUSED", not "UNUSED(var)" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As reported in [1] the "UNUSED(var)" macro introduced in 2174b8c75de (Merge branch 'jk/unused-annotation' into next, 2022-08-24) breaks coccinelle's parsing of our sources in files where it occurs. Let's instead partially go with the approach suggested in [2] of making this not take an argument. As noted in [1] "coccinelle" will ignore such tokens in argument lists that it doesn't know about, and it's less of a surprise to syntax highlighters. This undoes the "help us notice when a parameter marked as unused is actually use" part of 9b240347543 (git-compat-util: add UNUSED macro, 2022-08-19), a subsequent commit will further tweak the macro to implement a replacement for that functionality. 1. https://lore.kernel.org/git/220825.86ilmg4mil.gmgdl@evledraar.gmail.com/ 2. https://lore.kernel.org/git/220819.868rnk54ju.gmgdl@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- git-compat-util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index a9690126bb..5ea7be9749 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -190,9 +190,9 @@ struct strbuf; #define _SGI_SOURCE 1 #if defined(__GNUC__) -#define UNUSED(var) UNUSED_##var __attribute__((unused)) +#define UNUSED __attribute__((unused)) #else -#define UNUSED(var) UNUSED_##var +#define UNUSED #endif #if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */ @@ -403,9 +403,9 @@ typedef uintmax_t timestamp_t; #endif #ifndef platform_core_config -static inline int noop_core_config(const char *UNUSED(var), - const char *UNUSED(value), - void *UNUSED(cb)) +static inline int noop_core_config(const char *var UNUSED, + const char *value UNUSED, + void *cb UNUSED) { return 0; } @@ -499,7 +499,7 @@ static inline void extract_id_from_env(const char *env, uid_t *id) } static inline int is_path_owned_by_current_uid(const char *path, - struct strbuf *UNUSED(report)) + struct strbuf *report UNUSED) { struct stat st; uid_t euid; -- cgit v1.2.3 From 9ff7eb8c8882c477919acfe28a3d68bb58adf2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 25 Aug 2022 19:09:49 +0200 Subject: git-compat-util.h: use "deprecated" for UNUSED variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As noted in the preceding commit our "UNUSED" macro was no longer protecting against actual use of the "unused" variables, which it was previously doing by renaming the variable. Let's instead use the "deprecated" attribute to accomplish that goal. As [1] rightly notes this has the drawback that compiling with "-Wno-deprecated-declarations" will silence any such uses. I think the trade-off is worth it as: * We can consider that a feature, as e.g. backporting certain patches might use a now "unused" parameter, and the person doing that might want to silence it with DEVOPTS=no-error. * This way we play nicely with coccinelle, and any other dumb(er) parser of C (such as syntax highlighters). * Not every single compilation of git needs to catch "used but declared unused" parameters. It's sufficient that the default "make DEVELOPER=1" will do so, and that the "static-analysis" CI job will catch it. 1. https://lore.kernel.org/git/YwCtkwjWdJVHHZV0@coredump.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- git-compat-util.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 5ea7be9749..71a004be40 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -190,7 +190,8 @@ struct strbuf; #define _SGI_SOURCE 1 #if defined(__GNUC__) -#define UNUSED __attribute__((unused)) +#define UNUSED __attribute__((unused)) \ + __attribute__((deprecated ("parameter declared as UNUSED"))) #else #define UNUSED #endif -- cgit v1.2.3