Skip to content

Commit 43cbf36

Browse files
authored
Merge pull request swiftlang#31638 from compnerd/discarded-dependencies
runtime: add and switch to `SWIFT_NODISCARD` (NFC)
2 parents efc4e7d + 135f348 commit 43cbf36

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

stdlib/public/SwiftShims/RefCount.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class RefCountBitsT {
546546
// Returns true if the increment is a fast-path result.
547547
// Returns false if the increment should fall back to some slow path
548548
// (for example, because UseSlowRC is set or because the refcount overflowed).
549-
LLVM_NODISCARD SWIFT_ALWAYS_INLINE bool
549+
SWIFT_NODISCARD SWIFT_ALWAYS_INLINE bool
550550
incrementStrongExtraRefCount(uint32_t inc) {
551551
// This deliberately overflows into the UseSlowRC field.
552552
bits += BitsType(inc) << Offsets::StrongExtraRefCountShift;
@@ -557,7 +557,7 @@ class RefCountBitsT {
557557
// Returns false if the decrement should fall back to some slow path
558558
// (for example, because UseSlowRC is set
559559
// or because the refcount is now zero and should deinit).
560-
LLVM_NODISCARD SWIFT_ALWAYS_INLINE bool
560+
SWIFT_NODISCARD SWIFT_ALWAYS_INLINE bool
561561
decrementStrongExtraRefCount(uint32_t dec) {
562562
#ifndef NDEBUG
563563
if (!hasSideTable() && !isImmortal(false)) {
@@ -1409,8 +1409,8 @@ class HeapObjectSideTableEntry {
14091409

14101410

14111411
// WEAK
1412-
1413-
LLVM_NODISCARD
1412+
1413+
SWIFT_NODISCARD
14141414
HeapObjectSideTableEntry* incrementWeak() {
14151415
// incrementWeak need not be atomic w.r.t. concurrent deinit initiation.
14161416
// The client can't actually get a reference to the object without

stdlib/public/SwiftShims/Visibility.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149
#define SWIFT_FALLTHROUGH
150150
#endif
151151

152+
#if __cplusplus >= 201402l && __has_cpp_attribute(nodiscard)
153+
#define SWIFT_NODISCARD [[nodiscard]]
154+
#elif __has_cpp_attribute(clang::warn_unused_result)
155+
#define SWIFT_NODISCARD [[clang::warn_unused_result]]
156+
#else
157+
#define SWIFT_NODISCARD
158+
#endif
159+
152160

153161
/// Attributes for runtime-stdlib interfaces.
154162
/// Use these for C implementations that are imported into Swift via SwiftShims

0 commit comments

Comments
 (0)