Commit c617aea6 authored by Peter Eisentraut's avatar Peter Eisentraut

Add pg_nodiscard function declaration specifier

pg_nodiscard means the compiler should warn if the result of a
function call is ignored.  The name "nodiscard" is chosen in alignment
with (possibly future) C and C++ standards.  It maps to the GCC
attribute warn_unused_result.
Reviewed-by: default avatarMichael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/e3753562-99cd-b65f-5aca-687dfd1ec2fc@2ndquadrant.com
parent c77f6f50
...@@ -111,6 +111,18 @@ ...@@ -111,6 +111,18 @@
#define pg_attribute_unused() #define pg_attribute_unused()
#endif #endif
/*
* pg_nodiscard means the compiler should warn if the result of a function
* call is ignored. The name "nodiscard" is chosen in alignment with
* (possibly future) C and C++ standards. For maximum compatibility, use it
* as a function declaration specifier, so it goes before the return type.
*/
#ifdef __GNUC__
#define pg_nodiscard __attribute__((warn_unused_result))
#else
#define pg_nodiscard
#endif
/* /*
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
* used in assert-enabled builds, to avoid compiler warnings about unused * used in assert-enabled builds, to avoid compiler warnings about unused
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment