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

[PATCH 3/6] compat: disable -Wunused-parameter in 3rd-party code

From
Jeff King <peff@peff.net>
Date
Aug 28, 2024, 03:58 UTC
Message-ID
<20240828035855.GC3999193@coredump.intra.peff.net>
In-Reply-To
<20240828035722.GA3998881@coredump.intra.peff.net>

We carry some vendored 3rd-party code in compat/ that does not build cleanly with -Wunused-parameters. We could mark these with UNUSED, but there are two reasons not to:

  1. This is code imported from elsewhere, so we'd prefer to avoid
     modifying it in an invasive way that could create conflicts if we
     tried to pull in a new version.
  2. These files don't include git-compat-util.h at all, so we'd need to
     factor out (or repeat) our UNUSED macro.

In theory we could modify the build process to invoke the compiler with the extra warning disabled for these files, but there are tricky corner cases there (e.g., for NO_REGEX we cannot assume that the compiler understands -Wno-unused-parameter as an option, so we'd have to use our detect-compiler script).

Instead, let's rely on the gcc diagnostic #pragma. This is horribly unportable, of course, but it should do what we want. Compilers which don't understand this particular pragma should ignore it (per the standard), and compilers which do care about "-Wunused-parameter" will hopefully respect it, even if they are not gcc (e.g., clang does).

Signed-off-by: Jeff King <peff@peff.net>
---
 compat/nedmalloc/nedmalloc.c | 2 ++
 compat/regex/regcomp.c       | 2 ++
 2 files changed, 4 insertions(+)
diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 2c0ace7075..145255da43 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -31,6 +31,8 @@ DEALINGS IN THE SOFTWARE.
 /*#pragma optimize("a", on)*/
 #endif
 
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
 /*#define FULLSANITYCHECKS*/
 
 #include "nedmalloc.h"
diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c
index 6c5d455e92..8d93a9b93f 100644
--- a/compat/regex/regcomp.c
+++ b/compat/regex/regcomp.c
@@ -17,6 +17,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
 #if defined __TANDEM
  /* This is currently duplicated from git-compat-utils.h */
 # ifdef NO_INTPTR_T
-- 
2.46.0.754.g24c813f009
Previous: Jeff KingNext: Jeff King
Message 4 of 13 in “unused parameters: the final countdown”
  1. 0/6 unused parameters: the final countdownJeff King, Aug 28, 2024
  2. 1/6 gc: mark unused config parameter in virtual functionsJeff King, Aug 28, 2024
  3. 2/6 t-reftable-readwrite: mark unused parameter in callback functionJeff King, Aug 28, 2024
  4. 3/6 compat: disable -Wunused-parameter in 3rd-party codeJeff King, Aug 28, 2024
  5. 4/6 compat: disable -Wunused-parameter in win32/headless.cJeff King, Aug 28, 2024
  6. 5/6 compat: mark unused parameters in win32/mingw functionsJeff King, Aug 28, 2024
  7. 6/6 config.mak.dev: enable -Wunused-parameter by defaultJeff King, Aug 28, 2024
  8. Eric SunshineAug 28, 2024
  9. Patrick SteinhardtAug 28, 2024
  10. 7/6 CodingGuidelines: mention -Wunused-parameter and UNUSEDJeff King, Aug 28, 2024
  11. Eric SunshineAug 28, 2024
  12. Junio C HamanoAug 28, 2024
  13. Jeff KingAug 28, 2024

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.