chiark / gitweb /
utils/macros.h: Add `MUST_CHECK', so return codes aren't ignored.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 22 Dec 2022 17:10:27 +0000 (17:10 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 23 Apr 2023 19:23:21 +0000 (20:23 +0100)
utils/macros.3
utils/macros.h

index f5dac97705a18a6fe147542226b2be015016a595..d481a47f28c9e6d8958242b8a10730bc6a1fc310 100644 (file)
@@ -30,6 +30,7 @@ macros \- useful macros
 .\" @DEPRECATED
 .\" @EXECL_LIKE
 .\" @IGNORABLE
+.\" @MUST_CHECK
 .\" @NORETURN
 .\" @PRINTF_LIKE
 .\" @SCANF_LIKE
@@ -74,6 +75,7 @@ macros \- useful macros
 .BI "DEPRECATED(" msg ")"
 .BI "EXECL_LIKE(" ntrail ")"
 .BI "IGNORABLE"
+.BI "MUST_CHECK"
 .BI "NORETURN"
 .BI "PRINTF_LIKE(" fmt-index ", " arg-index ")"
 .BI "SCANF_LIKE(" fmt-index ", " arg-index ")"
@@ -193,6 +195,12 @@ need not be used.  This may muffle warnings about leaving the marked
 definition unused.
 .PP
 A function marked as
+.B MUST_CHECK
+returns an important value: a warning may be issued if a caller
+ignores the value.  The return type must not be
+.BR void .
+.PP
+A function marked as
 .B NORETURN
 must not return.  It must have return type
 .BR void .
index 45420e2232d1210ae55c4643b825bdb7103d3333..70f535fe51a28ca5a28f28734b7e6d08568dda0c 100644 (file)
 #  define IGNORABLE __attribute__((__unused__))
 #endif
 
+#if GCC_VERSION_P(3, 4) || CLANG_VERSION_P(3, 3)
+#  define MUST_CHECK __attribute__((__warn_unused_result__))
+#endif
+
 #if GCC_VERSION_P(4, 5) || CLANG_VERSION_P(3, 3)
 #  define DEPRECATED(msg) __attribute__((__deprecated__(msg)))
 #elif GCC_VERSION_P(3, 1)
 #  define IGNORABLE
 #endif
 
+#ifndef MUST_CHECK
+#  define MUST_CHECK
+#endif
+
 #ifndef GCC_WARNING
 #  define GCC_WARNING(warn)
 #endif