Skip to content

Commit 7d0fa2c

Browse files
Add NODISCARD macro
This is used to mark functions for which the result should not be ignored, and can be checked by some compilers.
1 parent 8fec047 commit 7d0fa2c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/util/nodiscard.h

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

0 commit comments

Comments
 (0)