Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_atomic_min_max`` *unimplemented*
---------------------------------------------------------- -----------------
``__cpp_lib_atomic_ref`` ``202411L``
---------------------------------------------------------- -----------------
``__cpp_lib_bind_front`` ``202306L``
---------------------------------------------------------- -----------------
``__cpp_lib_bitset`` ``202306L``
Expand Down
1 change: 1 addition & 0 deletions libcxx/docs/ReleaseNotes/22.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Implemented Papers
- P3044R2: sub-``string_view`` from ``string`` (`Github <https://llvm.org/PR148140>`__)
- P3223R2: Making ``std::istream::ignore`` less surprising (`Github <https://llvm.org/PR148178>`__)
- P3060R3: Add ``std::views::indices(n)`` (`Github <https://llvm.org/PR148175>`__)
- P2835R7: Expose ``std::atomic_ref``'s object address (`Github <https://llvm.org/PR118377>`__)
- P3168R2: Give ``std::optional`` Range Support (`Github <https://llvm.org/PR105430>`__)

Improvements and New Features
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx2cPapers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"`P3222R0 <https://wg21.link/P3222R0>`__","Fix C++26 by adding transposed special cases for P2642 layouts","2024-11 (Wrocław)","","","`#118374 <https://github.com/llvm/llvm-project/issues/118374>`__",""
"`P3050R2 <https://wg21.link/P3050R2>`__","Fix C++26 by optimizing ``linalg::conjugated`` for noncomplex value types","2024-11 (Wrocław)","","","`#118375 <https://github.com/llvm/llvm-project/issues/118375>`__",""
"`P3396R1 <https://wg21.link/P3396R1>`__","``std::execution`` wording fixes","2024-11 (Wrocław)","","","`#118376 <https://github.com/llvm/llvm-project/issues/118376>`__",""
"`P2835R7 <https://wg21.link/P2835R7>`__","Expose ``std::atomic_ref``'s object address","2024-11 (Wrocław)","","","`#118377 <https://github.com/llvm/llvm-project/issues/118377>`__",""
"`P2835R7 <https://wg21.link/P2835R7>`__","Expose ``std::atomic_ref``'s object address","2024-11 (Wrocław)","|Complete|","22","`#118377 <https://github.com/llvm/llvm-project/issues/118377>`__",""
"`P3323R1 <https://wg21.link/P3323R1>`__","cv-qualified types in ``atomic`` and ``atomic_ref``","2024-11 (Wrocław)","","","`#118378 <https://github.com/llvm/llvm-project/issues/118378>`__",""
"`P3508R0 <https://wg21.link/P3508R0>`__","Wording for ""constexpr for specialized memory algorithms""","2024-11 (Wrocław)","","","`#118379 <https://github.com/llvm/llvm-project/issues/118379>`__",""
"`P3369R0 <https://wg21.link/P3369R0>`__","constexpr for ``uninitialized_default_construct``","2024-11 (Wrocław)","","","`#118380 <https://github.com/llvm/llvm-project/issues/118380>`__",""
Expand Down
3 changes: 3 additions & 0 deletions libcxx/include/__atomic/atomic_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ struct __atomic_ref_base {
}
_LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept { std::__atomic_notify_one(*this); }
_LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); }
# if _LIBCPP_STD_VER >= 26
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp* address() const noexcept { return __ptr_; }
# endif

protected:
using _Aligned_Tp [[__gnu__::__aligned__(required_alignment), __gnu__::__nodebug__]] = _Tp;
Expand Down
5 changes: 4 additions & 1 deletion libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ __cpp_lib_atomic_float 201711L <atomic>
__cpp_lib_atomic_is_always_lock_free 201603L <atomic>
__cpp_lib_atomic_lock_free_type_aliases 201907L <atomic>
__cpp_lib_atomic_min_max 202403L <atomic>
__cpp_lib_atomic_ref 201806L <atomic>
__cpp_lib_atomic_ref 202411L <atomic>
201806L // C++20
__cpp_lib_atomic_shared_ptr 201711L <atomic>
__cpp_lib_atomic_value_initialization 201911L <atomic> <memory>
__cpp_lib_atomic_wait 201907L <atomic>
Expand Down Expand Up @@ -544,6 +545,8 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_aligned_accessor 202411L
// # define __cpp_lib_associative_heterogeneous_insertion 202306L
// # define __cpp_lib_atomic_min_max 202403L
# undef __cpp_lib_atomic_ref
# define __cpp_lib_atomic_ref 202411L
# undef __cpp_lib_bind_front
# define __cpp_lib_bind_front 202306L
# define __cpp_lib_bitset 202306L
Expand Down
33 changes: 33 additions & 0 deletions libcxx/test/libcxx/diagnostics/atomic.nodiscard.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++26

// check that <atomic> functions are marked [[nodiscard]]

#include <atomic>

#include "atomic_helpers.h"
#include "test_macros.h"

template <typename T>
struct TestAtomicRef {
void operator()() const {
T x(T(1));
const std::atomic_ref<T> a(x);

a.address(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}}
}
};

void test() {
TestAtomicRef<UserAtomicType>()();
TestAtomicRef<int>()();
TestAtomicRef<float>()();
TestAtomicRef<char*>()();
}
37 changes: 37 additions & 0 deletions libcxx/test/std/atomics/atomics.ref/address.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++26

// constexpr T* address() const noexcept;

#include <atomic>
#include <cassert>
#include <concepts>
#include <memory>

#include "atomic_helpers.h"
#include "test_macros.h"

template <typename T>
struct TestAddress {
void operator()() const {
T x(T(1));
const std::atomic_ref<T> a(x);

std::same_as<T*> decltype(auto) p = a.address();
assert(std::addressof(x) == p);

static_assert(noexcept((a.address())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constexpr on address doesn't seem tested. I think it's better to reorganize TestAddress to test constexpr together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that we haven't added constexpr to the constructor. Perhaps test for constexpr should be done in another PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to complete it after #118382 (P3309R3: constexpr atomic and atomic_ref)

}
};

int main(int, char**) {
TestEachAtomicType<TestAddress>()();

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@
# ifndef __cpp_lib_atomic_ref
# error "__cpp_lib_atomic_ref should be defined in c++26"
# endif
# if __cpp_lib_atomic_ref != 201806L
# error "__cpp_lib_atomic_ref should have the value 201806L in c++26"
# if __cpp_lib_atomic_ref != 202411L
# error "__cpp_lib_atomic_ref should have the value 202411L in c++26"
# endif

# if !defined(_LIBCPP_VERSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6325,8 +6325,8 @@
# ifndef __cpp_lib_atomic_ref
# error "__cpp_lib_atomic_ref should be defined in c++26"
# endif
# if __cpp_lib_atomic_ref != 201806L
# error "__cpp_lib_atomic_ref should have the value 201806L in c++26"
# if __cpp_lib_atomic_ref != 202411L
# error "__cpp_lib_atomic_ref should have the value 202411L in c++26"
# endif

# if !defined(_LIBCPP_VERSION)
Expand Down
5 changes: 4 additions & 1 deletion libcxx/utils/generate_feature_test_macro_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ def add_version_header(tc):
},
{
"name": "__cpp_lib_atomic_ref",
"values": {"c++20": 201806},
"values": {
"c++20": 201806,
"c++26": 202411, # P2835R7: Expose std::atomic_ref 's object address
},
"headers": ["atomic"],
},
{
Expand Down
Loading