Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c617aea

Browse filesBrowse 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
Copy full SHA for c617aea

File tree

Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed

‎src/include/c.h

Copy file name to clipboardExpand all lines: src/include/c.h
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.