From b876381b72ba11667a1d54a097c400334275247e Mon Sep 17 00:00:00 2001 From: nhmall Date: Thu, 7 Aug 2025 21:47:40 -0400 Subject: [PATCH] add support for [[maybe_unused]] if available --- include/tradstdc.h | 16 ++++++++++++++++ src/report.c | 4 +++- win/share/tilemap.c | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/tradstdc.h b/include/tradstdc.h index adcfa0619..4c304b625 100644 --- a/include/tradstdc.h +++ b/include/tradstdc.h @@ -389,6 +389,14 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #define FALLTHROUGH [[fallthrough]] /* #warning [[fallthrough]] from C23 */ #endif /* __has_c_attribute(fallthrough) */ +/* + * maybe_unused + */ +#if __has_c_attribute(maybe_unused) +#ifndef ATTRUNUSED +#define ATTRUNUSED [[maybe_unused]] +#endif +#endif /* __has_c_attribute(maybe_unused) */ #endif /* NH_C >= 202300L */ /* @@ -416,7 +424,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #define PRINTF_F_PTR(f, v) PRINTF_F(f, v) #endif #if __GNUC__ >= 3 +#ifndef ATTRUNUSED #define UNUSED __attribute__((unused)) +#endif #ifndef ATTRNORETURN #ifndef NORETURN #define NORETURN __attribute__((noreturn)) @@ -496,6 +506,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #define NH_PRAGMA_MESSAGE 1 #endif /* _MSC_VER */ +#if !defined(UNUSED) && defined(ATTRUNUSED) +#define UNUSED ATTRUNUSED +#endif /* Fallback implementations */ #ifndef PRINTF_F @@ -507,6 +520,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #ifndef UNUSED #define UNUSED #endif +#ifndef ATTRUNUSED +#define ATTRUNUSED +#endif #ifndef FALLTHROUGH #define FALLTHROUGH #endif diff --git a/src/report.c b/src/report.c index 3eb8fd5aa..ecfa0ad17 100644 --- a/src/report.c +++ b/src/report.c @@ -110,7 +110,7 @@ static char bid[40]; /* ARGSUSED */ void -crashreport_init(int argc UNUSED, char *argv[] UNUSED) +crashreport_init(int argc, char *argv[]) { static int once = 0; if (once++) /* NetHackW.exe calls us twice */ @@ -169,6 +169,8 @@ crashreport_init(int argc UNUSED, char *argv[] UNUSED) Strcpy(bid, "unknown"); HASH_CLEANUP(ctxp); HASH_PRAGMA_END + nhUse(argc); + nhUse(argv); } #undef HASH_CONTEXTPTR diff --git a/win/share/tilemap.c b/win/share/tilemap.c index a28cd8c76..832bae769 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -1311,7 +1311,7 @@ extern void objects_globals_init(void); DISABLE_WARNING_UNREACHABLE_CODE int -main(int argc UNUSED, char *argv[] UNUSED) +main(int argc, char *argv[]) { int i, tilenum; char filename[30]; @@ -1395,6 +1395,8 @@ main(int argc UNUSED, char *argv[] UNUSED) free_tilerefs(); exit(EXIT_SUCCESS); /*NOTREACHED*/ + nhUse(argc); + nhUse(argv); return 0; } @@ -1491,7 +1493,7 @@ add_tileref( const char *prefix) { struct tiles_used temp = { 0 }; - static const char ellipsis[] UNUSED = "..."; + static const char ellipsis[] = "..."; char buf[BUFSZ]; if (!tilelist[n]) { @@ -1519,6 +1521,7 @@ add_tileref( (strlen(temp.references) >= (sizeof temp.references - 7) - 1) ? buf : ""); + nhUse(ellipsis); } void