Created on 2022-01-21.00:00:00 last changed 12 months ago
Proposed resolution:
This wording is relative to N4901.
Modify [util.smartptr.atomic.shared], class template partial specialization atomic<shared_ptr<T>> synopsis, as indicated:
[…] constexpr atomic() noexcept; constexpr atomic(nullptr_t) noexcept : atomic() { } atomic(shared_ptr<T> desired) noexcept; atomic(const atomic&) = delete; void operator=(const atomic&) = delete; […]
[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]
[ 2022-01-30; Reflector poll ]
Set status to Tentatively Ready after seven votes in favour during reflector poll.
All the following are valid except for the last line:
constinit int i1{};
constinit std::atomic<int> a1{};
constinit int i2{0};
constinit std::atomic<int> a2{0};
constinit std::shared_ptr<int> i3{};
constinit std::atomic<std::shared_ptr<int>> a3{};
constinit std::shared_ptr<int> i4{nullptr};
constinit std::atomic<std::shared_ptr<int>> a4{nullptr}; // error
The initializer for a4 will create a shared_ptr<int> temporary (using the same constructor as i4) but then try to use atomic(shared_ptr<int>) which is not constexpr.
This is an unnecessary inconsistency in the API for atomic<shared_ptr<T>> that can easily be fixed. The proposed resolution has been implemented in libstdc++. There is no need to also change atomic<weak_ptr<T>> because weak_ptr doesn't have a constructor taking nullptr.History | |||
---|---|---|---|
Date | User | Action | Args |
2023-11-22 15:47:43 | admin | set | status: wp -> c++23 |
2022-02-10 12:58:57 | admin | set | messages: + msg12365 |
2022-02-10 12:58:57 | admin | set | status: ready -> wp |
2022-01-30 17:01:07 | admin | set | messages: + msg12310 |
2022-01-30 17:01:07 | admin | set | status: new -> ready |
2022-01-22 13:34:40 | admin | set | messages: + msg12274 |
2022-01-21 00:00:00 | admin | create |