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.
This commit is contained in:
ridiculousfish 2020-07-25 12:39:06 -07:00
parent e5cff1a2db
commit 364c6001dc

View File

@ -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