From 364c6001dc827ff7b0ee3bc209ddccab36bf2a7f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 25 Jul 2020 12:39:06 -0700 Subject: [PATCH] Introduce __warn_unused_type This is like __warn_unused, but it says that any time this type is returned from a function it must be used. This will help enforce error handling. --- config_cmake.h.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config_cmake.h.in b/config_cmake.h.in index 35e9d764f..2a8532d2f 100644 --- a/config_cmake.h.in +++ b/config_cmake.h.in @@ -170,6 +170,7 @@ /* Define to 1 if mbrtowc attempts to convert invalid UTF-8 sequences */ #cmakedefine HAVE_BROKEN_MBRTOWC_UTF8 1 +/* Support __warn_unused on function return values. */ #if __GNUC__ >= 3 #ifndef __warn_unused #define __warn_unused __attribute__ ((warn_unused_result)) @@ -177,3 +178,14 @@ #else #define __warn_unused #endif + +/* Like __warn_unused, but applies to a type. + At the moment only clang supports this as a type attribute. +*/ +#if defined(__clang__) && __has_attribute(warn_unused_result) +#ifndef __warn_unused_type +#define __warn_unused_type __attribute__ ((warn_unused_result)) +#endif +#else +#define __warn_unused_type +#endif