Skip to content

Commit be28284

Browse files
committed
Add nodiscard utility
This just substitutes for `[[nodiscard]]` until we use C++17 -- most modern GNU or GNU-compatible compilers will give us a similar utility in the meantime.
1 parent b2d7a5a commit be28284

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/util/nodiscard.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*******************************************************************\
2+
3+
Module: No-discard-result macro
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// No-discard-result macro
11+
12+
#ifndef CPROVER_UTIL_NODISCARD_H
13+
#define CPROVER_UTIL_NODISCARD_H
14+
15+
#if __has_cpp_attribute(nodiscard)
16+
# ifdef __clang__
17+
# pragma GCC diagnostic ignored "-Wc++17-extensions"
18+
# endif
19+
# define NODISCARD [[nodiscard]] // NOLINT
20+
#elif __has_cpp_attribute(gnu::warn_unused_result)
21+
# define NODISCARD [[gnu::warn_unused_result]] // NOLINT
22+
#else
23+
# define NODISCARD
24+
#endif
25+
26+
#endif

0 commit comments

Comments
 (0)