Skip to content

Commit c617aea

Browse files
committed
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
1 parent c77f6f5 commit c617aea

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/include/c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@
111111
#define pg_attribute_unused()
112112
#endif
113113

114+
/*
115+
* pg_nodiscard means the compiler should warn if the result of a function
116+
* call is ignored. The name "nodiscard" is chosen in alignment with
117+
* (possibly future) C and C++ standards. For maximum compatibility, use it
118+
* as a function declaration specifier, so it goes before the return type.
119+
*/
120+
#ifdef __GNUC__
121+
#define pg_nodiscard __attribute__((warn_unused_result))
122+
#else
123+
#define pg_nodiscard
124+
#endif
125+
114126
/*
115127
* Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
116128
* used in assert-enabled builds, to avoid compiler warnings about unused

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy