diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2020-10-17 08:38:39 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2020-11-11 11:00:27 +0100 |
commit | c617aea6acdd9057a14d91ff294905b1b5509348 (patch) | |
tree | 9745f24103d647ebb7924e3dbdfa6e71b7c5421c /src/include/c.h | |
parent | c77f6f50e4187bed38d1d36ae16b0c248e286d15 (diff) | |
download | postgresql-c617aea6acdd9057a14d91ff294905b1b5509348.tar.gz |
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: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/e3753562-99cd-b65f-5aca-687dfd1ec2fc@2ndquadrant.com
Diffstat (limited to 'src/include/c.h')
-rw-r--r-- | src/include/c.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/include/c.h b/src/include/c.h index 9cd67f8f76..d5dc3632f7 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -112,6 +112,18 @@ #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 * used in assert-enabled builds, to avoid compiler warnings about unused * variables in assert-disabled builds. |