Skip to content

Commit e637ccd

Browse files
committed
Runtimes: resync from branch (NFCI)
This restores the `LLVM_NODISCARD` macro from the branch point (retaining the header inclusion changes). This is required to build SwiftRemoteMirror without injecting another LLVM build.
1 parent e9f19fc commit e637ccd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

stdlib/include/llvm/Support/Compiler.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@
142142
#define LLVM_ATTRIBUTE_USED
143143
#endif
144144

145+
/// LLVM_NODISCARD - Warn if a type or return value is discarded.
146+
147+
// Use the 'nodiscard' attribute in C++17 or newer mode.
148+
#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
149+
#define LLVM_NODISCARD [[nodiscard]]
150+
#elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
151+
#define LLVM_NODISCARD [[clang::warn_unused_result]]
152+
// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also
153+
// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).
154+
// Use the 'nodiscard' attribute in C++14 mode only with GCC.
155+
// TODO: remove this workaround when PR33518 is resolved.
156+
#elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
157+
#define LLVM_NODISCARD [[nodiscard]]
158+
#else
159+
#define LLVM_NODISCARD
160+
#endif
161+
145162
// Indicate that a non-static, non-const C++ member function reinitializes
146163
// the entire object to a known state, independent of the previous state of
147164
// the object.

0 commit comments

Comments
 (0)