-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Allow atomic_ref<const T> #1500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow atomic_ref<const T> #1500
Conversation
|
I believe non-copy-constructible yet copy-assignable types would not be valid. According to https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable a type is only trivially copyable iff:
So a type that is not copy-constructible cannot be trivially copyable |
miscco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and given the requirements on trivially-copyable I believe the changes are correct
|
Thanks for reviewing my code, I appreciate it! 😸
Clang, GCC, and MSVC accept this: https://godbolt.org/z/W4zrnY #include <type_traits>
using namespace std;
struct Integer {
int n{0};
Integer() = default;
Integer(const Integer&) = delete;
Integer& operator=(const Integer&) = default;
};
static_assert(is_trivially_copyable_v<Integer>);
static_assert(!is_copy_constructible_v<Integer>);
static_assert(is_copy_assignable_v<Integer>);
static_assert(is_trivially_copy_assignable_v<Integer>);
int main() {} |
|
Ah, reading it again, it an exclusive list http://eel.is/c++draft/class.prop#1 |
|
I would not expect |
|
Ah, you mean separate test for non-constant odd type? Ok, then it is really an interesting case |
Fixes #1497. While
atomicandatomic_refare similar in many ways, they need differentstatic_asserts:✔️
atomicWG21-N4868 31.8.1 [atomics.types.generic.general]/1: "The program is ill-formed if any of
is_trivially_copyable_v<T>,is_copy_constructible_v<T>,is_move_constructible_v<T>,is_copy_assignable_v<T>, oris_move_assignable_v<T>isfalse."STL/stl/inc/atomic
Lines 2165 to 2168 in 19c683d
🪲
atomic_refWG21-N4868 31.7.1 [atomics.ref.generic.general]/2: "The program is ill-formed if
is_trivially_copyable_v<T>is false."STL/stl/inc/atomic
Lines 2350 to 2353 in 19c683d
Testing
I looked into testing a non-copy-constructible, yet trivially-copy-assignable, type. However, because
atomic_ref::storepassesTby value, it appears that this doesn't actually work, and it's unclear from the Standardese whether it's supposed to. So, this PR simply fixes thestatic_assertto match the Standardese and testsatomic_ref<const int>.