File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff 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
227227protected:
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1515#include < atomic>
1616#include < cassert>
1717#include < concepts>
18+ #include < memory>
1819
1920#include " atomic_helpers.h"
2021#include " test_macros.h"
You can’t perform that action at this time.
0 commit comments