Skip to content

Commit 8b61107

Browse files
committed
Addressed review comments
1 parent 037a1cb commit 8b61107

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

libcxx/include/__atomic/atomic_ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct __atomic_ref_base {
221221
_LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept { std::__atomic_notify_one(*this); }
222222
_LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); }
223223
# if _LIBCPP_STD_VER >= 26
224-
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* address() const noexcept { return __ptr_; }
224+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* address() const noexcept { return __ptr_; }
225225
# endif
226226

227227
protected:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// check that <atomic> functions are marked [[nodiscard]]
12+
13+
// clang-format off
14+
15+
#include <atomic>
16+
17+
#include "atomic_helpers.h"
18+
#include "test_macros.h"
19+
20+
template <typename T>
21+
struct TestAtomicRef {
22+
void operator()() const {
23+
T x(T(1));
24+
const std::atomic_ref<T> a(x);
25+
26+
#if TEST_STD_VER >= 26
27+
a.address(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}}
28+
#endif
29+
}
30+
};
31+
32+
void test() {
33+
TestAtomicRef<UserAtomicType>()();
34+
TestAtomicRef<int>()();
35+
TestAtomicRef<float>()();
36+
TestAtomicRef<char*>()();
37+
}

libcxx/test/std/atomics/atomics.ref/address.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <atomic>
1616
#include <cassert>
1717
#include <concepts>
18+
#include <memory>
1819

1920
#include "atomic_helpers.h"
2021
#include "test_macros.h"

0 commit comments

Comments
 (0)