From a9436f131132f5b80ca0a860810b1ec36db09a56 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 26 Sep 2022 15:49:42 -0700 Subject: [PATCH] __attribute__(returns_nonnull) Refine commit 4885653014e6651118e58315e95c7655539ca21b. > I'm not sure whether gcc 3 is really the right test for whether the > returns_nonnull attribute setting is available. The gcc.gnu.org website only goes back to 5.1, and searching the documentation of that version for returns_nonnull finds it. I used ftp to get gcc-core-3.0.0 and gcc-core-4.0.0 and their doc files don't mention this attribute. It might have been added for some later 4.x but that really doesn't matter for nethack's purposes. Use __GNUC__ >= 5 instead of __GNUC__ >= 3 when testing whether __attribute__(returns_nonnull) is available. --- include/tradstdc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/tradstdc.h b/include/tradstdc.h index 68da53777..734c337e6 100644 --- a/include/tradstdc.h +++ b/include/tradstdc.h @@ -389,7 +389,7 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #ifdef __clang__ /* clang's gcc emulation is sufficient for nethack's usage */ #ifndef __GNUC__ -#define __GNUC__ 4 +#define __GNUC__ 5 /* high enough for returns_nonnull */ #endif #endif @@ -404,7 +404,6 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #if __GNUC__ >= 3 #define UNUSED __attribute__((unused)) #define NORETURN __attribute__((noreturn)) -#define NONNULL __attribute__((returns_nonnull)) #if !defined(__linux__) || defined(GCC_URWARN) /* disable gcc's __attribute__((__warn_unused_result__)) since explicitly discarding the result by casting to (void) is not accepted as a 'use' */ @@ -412,6 +411,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #define warn_unused_result /*empty*/ #endif #endif +#if __GNUC__ >= 5 +#define NONNULL __attribute__((returns_nonnull)) +#endif #endif #ifndef PRINTF_F