]> granicus.if.org Git - nethack/commitdiff
__attribute__(returns_nonnull)
authorPatR <rankin@nethack.org>
Mon, 26 Sep 2022 22:49:42 +0000 (15:49 -0700)
committerPatR <rankin@nethack.org>
Mon, 26 Sep 2022 22:49:42 +0000 (15:49 -0700)
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

index 68da5377755b8bbf5a6702e465d7d8b7b15bd582..734c337e65f6a753574c5b9b178555d246e12805 100644 (file)
@@ -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