git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git-compat-util.h: use "deprecated" for UNUSED variables

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 25, 2022, 17:09 UTC
Message-ID
<patch-2.2-0f603594e5e-20220825T170709Z-avarab@gmail.com>
In-Reply-To
<cover-0.2-00000000000-20220825T170709Z-avarab@gmail.com>

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 <avarab@gmail.com>
---
 git-compat-util.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 5ea7be97493..71a004be409 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
-- 
2.37.2.1279.g8741a0e3ea3
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 10 of 26 in “ci: update 'static-analysis' to Ubuntu 22.04”
  1. ci: update 'static-analysis' to Ubuntu 22.04Derrick Stolee via GitGitGadget, Aug 23, 2022
  2. Johannes SchindelinAug 24, 2022
  3. Junio C HamanoAug 24, 2022
  4. Junio C HamanoAug 24, 2022
  5. Derrick StoleeAug 25, 2022
  6. Junio C HamanoAug 25, 2022
  7. Ævar Arnfjörð BjarmasonAug 25, 2022
  8. Junio C HamanoAug 25, 2022
  9. 0/2 git-compat-util.h: change UNUSED(var) to UNUSEDÆvar Arnfjörð Bjarmason, Aug 25, 2022
  10. 2/2 git-compat-util.h: use "deprecated" for UNUSED variablesÆvar Arnfjörð Bjarmason, Aug 25, 2022
  11. 1/2 git-compat-util.h: use "UNUSED", not "UNUSED(var)"Ævar Arnfjörð Bjarmason, Aug 25, 2022
  12. Jeff KingAug 26, 2022
  13. Jeff KingAug 26, 2022
  14. Junio C HamanoAug 26, 2022
  15. Jeff KingAug 27, 2022
  16. Junio C HamanoAug 29, 2022
  17. Ævar Arnfjörð BjarmasonAug 29, 2022
  18. Jeff KingAug 31, 2022
  19. SZEDER GáborAug 31, 2022
  20. Ævar Arnfjörð BjarmasonAug 31, 2022
  21. Jeff KingAug 31, 2022
  22. Junio C HamanoAug 31, 2022
  23. SZEDER GáborAug 31, 2022
  24. Ævar Arnfjörð BjarmasonAug 31, 2022
  25. Ævar Arnfjörð BjarmasonAug 25, 2022
  26. Junio C HamanoAug 25, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.