-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] std::atomic primary template should not have a difference_type member type
#123236
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3695367
Apply clang-format
dalg24 857e15f
Fix tests for std::atomic member types
dalg24 c1ea966
Fix std::atomic primary template should not have difference_type
dalg24 af4d5f5
Update expected error for atomic_fetch_{add,sub}[_explicit] with poin…
dalg24 95a84d4
Add test with function pointer
dalg24 145d45a
Fixup for cxx03
dalg24 163a79a
Apply suggested changes from review
dalg24 64257b4
Add XFAIL directive for the frozen cxx03 tests per review
dalg24 fc2dc57
Merge branch 'main' of https://github.com/llvm/llvm-project into atom…
dalg24 f16cd7b
Fixup missing typename keyword
dalg24 bacb6bb
Fixup std::atomic<Floating>::difference_type was introduced in C++20
dalg24 fbaebba
Merge branch 'main' into atomic_difference_type
ldionne 0e2b81f
XFAIL test in C++03 frozen
ldionne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,163 +29,176 @@ | |
| # include <thread> | ||
| #endif | ||
|
|
||
| template <class A, bool Integral> | ||
| struct test_atomic | ||
| { | ||
| test_atomic() | ||
| { | ||
| A a; (void)a; | ||
| // detect existence of the difference_type member type | ||
| template <class...> | ||
| using myvoid_t = void; | ||
| template <typename T, typename = void> | ||
| struct has_difference_type : std::false_type {}; | ||
| template <typename T> | ||
| struct has_difference_type<T, myvoid_t<typename T::difference_type> > : std::true_type {}; | ||
|
|
||
| template <class A, bool IntegralOrFloating, bool Pointer> | ||
dalg24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| struct test_atomic { | ||
| test_atomic() { | ||
| static_assert(!IntegralOrFloating || !Pointer, ""); | ||
dalg24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| A a; | ||
| (void)a; | ||
| #if TEST_STD_VER >= 17 | ||
| static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); | ||
| static_assert(!has_difference_type<A>::value, ""); | ||
| #endif | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| template <class A> | ||
| struct test_atomic<A, true> | ||
| { | ||
| test_atomic() | ||
| { | ||
| A a; (void)a; | ||
| struct test_atomic<A, true, false> { | ||
| test_atomic() { | ||
| A a; | ||
| (void)a; | ||
| #if TEST_STD_VER >= 17 | ||
| static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); | ||
| static_assert((std::is_same_v<typename A::value_type, typename A::difference_type>), ""); | ||
| #endif | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| template <class A> | ||
| struct test_atomic<A*, false> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would never occur since we were instantiating with |
||
| { | ||
| test_atomic() | ||
| { | ||
| A a; (void)a; | ||
| struct test_atomic<A, false, true> { | ||
| test_atomic() { | ||
| A a; | ||
| (void)a; | ||
| #if TEST_STD_VER >= 17 | ||
| static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); | ||
| static_assert((std::is_same_v<typename A::difference_type, std::ptrdiff_t>), ""); | ||
| #endif | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| template <class T> | ||
| void | ||
| test() | ||
| { | ||
| using A = std::atomic<T>; | ||
| void test() { | ||
| using A = std::atomic<T>; | ||
| #if TEST_STD_VER >= 17 | ||
| static_assert((std::is_same_v<typename A::value_type, T>), ""); | ||
| static_assert((std::is_same_v<typename A::value_type, T>), ""); | ||
| #endif | ||
| test_atomic<A, std::is_integral<T>::value && !std::is_same<T, bool>::value>(); | ||
| enum { | ||
| IntegralOrFloating = | ||
| (std::is_integral<T>::value && !std::is_same<T, bool>::value) || std::is_floating_point<T>::value | ||
| }; | ||
| enum { Pointer = std::is_pointer<T>::value }; | ||
| test_atomic<A, IntegralOrFloating, Pointer>(); | ||
| } | ||
|
|
||
| struct TriviallyCopyable { | ||
| int i_; | ||
| int i_; | ||
| }; | ||
|
|
||
| struct WeirdTriviallyCopyable | ||
| { | ||
| char i, j, k; /* the 3 chars of doom */ | ||
| struct WeirdTriviallyCopyable { | ||
| char i, j, k; /* the 3 chars of doom */ | ||
| }; | ||
|
|
||
| struct PaddedTriviallyCopyable | ||
| { | ||
| char i; int j; /* probably lock-free? */ | ||
| struct PaddedTriviallyCopyable { | ||
| char i; | ||
| int j; /* probably lock-free? */ | ||
| }; | ||
|
|
||
| struct LargeTriviallyCopyable | ||
| { | ||
| int i, j[127]; /* decidedly not lock-free */ | ||
| struct LargeTriviallyCopyable { | ||
| int i, j[127]; /* decidedly not lock-free */ | ||
| }; | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| test<bool> (); | ||
| test<char> (); | ||
| test<signed char> (); | ||
| test<unsigned char> (); | ||
| test<short> (); | ||
| test<unsigned short> (); | ||
| test<int> (); | ||
| test<unsigned int> (); | ||
| test<long> (); | ||
| test<unsigned long> (); | ||
| test<long long> (); | ||
| test<unsigned long long> (); | ||
| int main(int, char**) { | ||
| test<bool>(); | ||
| test<char>(); | ||
| test<signed char>(); | ||
| test<unsigned char>(); | ||
| test<short>(); | ||
| test<unsigned short>(); | ||
| test<int>(); | ||
| test<unsigned int>(); | ||
| test<long>(); | ||
| test<unsigned long>(); | ||
| test<long long>(); | ||
| test<unsigned long long>(); | ||
| #if TEST_STD_VER > 17 && defined(__cpp_char8_t) | ||
| test<char8_t> (); | ||
| test<char8_t>(); | ||
| #endif | ||
| test<char16_t> (); | ||
| test<char32_t> (); | ||
| test<char16_t>(); | ||
| test<char32_t>(); | ||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t> (); | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| test<std::int_least8_t> (); | ||
| test<std::uint_least8_t> (); | ||
| test<std::int_least16_t> (); | ||
| test<std::uint_least16_t> (); | ||
| test<std::int_least32_t> (); | ||
| test<std::uint_least32_t> (); | ||
| test<std::int_least64_t> (); | ||
| test<std::uint_least64_t> (); | ||
|
|
||
| test<std::int_fast8_t> (); | ||
| test<std::uint_fast8_t> (); | ||
| test<std::int_fast16_t> (); | ||
| test<std::uint_fast16_t> (); | ||
| test<std::int_fast32_t> (); | ||
| test<std::uint_fast32_t> (); | ||
| test<std::int_fast64_t> (); | ||
| test<std::uint_fast64_t> (); | ||
|
|
||
| test< std::int8_t> (); | ||
| test<std::uint8_t> (); | ||
| test< std::int16_t> (); | ||
| test<std::uint16_t> (); | ||
| test< std::int32_t> (); | ||
| test<std::uint32_t> (); | ||
| test< std::int64_t> (); | ||
| test<std::uint64_t> (); | ||
|
|
||
| test<std::intptr_t> (); | ||
| test<std::uintptr_t> (); | ||
| test<std::size_t> (); | ||
| test<std::ptrdiff_t> (); | ||
| test<std::intmax_t> (); | ||
| test<std::uintmax_t> (); | ||
|
|
||
| test<std::uintmax_t> (); | ||
| test<std::uintmax_t> (); | ||
|
|
||
| test<TriviallyCopyable>(); | ||
| test<PaddedTriviallyCopyable>(); | ||
| test<std::int_least8_t>(); | ||
| test<std::uint_least8_t>(); | ||
| test<std::int_least16_t>(); | ||
| test<std::uint_least16_t>(); | ||
| test<std::int_least32_t>(); | ||
| test<std::uint_least32_t>(); | ||
| test<std::int_least64_t>(); | ||
| test<std::uint_least64_t>(); | ||
|
|
||
| test<std::int_fast8_t>(); | ||
| test<std::uint_fast8_t>(); | ||
| test<std::int_fast16_t>(); | ||
| test<std::uint_fast16_t>(); | ||
| test<std::int_fast32_t>(); | ||
| test<std::uint_fast32_t>(); | ||
| test<std::int_fast64_t>(); | ||
| test<std::uint_fast64_t>(); | ||
|
|
||
| test< std::int8_t>(); | ||
| test<std::uint8_t>(); | ||
| test< std::int16_t>(); | ||
| test<std::uint16_t>(); | ||
| test< std::int32_t>(); | ||
| test<std::uint32_t>(); | ||
| test< std::int64_t>(); | ||
| test<std::uint64_t>(); | ||
|
|
||
| test<std::intptr_t>(); | ||
| test<std::uintptr_t>(); | ||
| test<std::size_t>(); | ||
| test<std::ptrdiff_t>(); | ||
| test<std::intmax_t>(); | ||
| test<std::uintmax_t>(); | ||
|
|
||
| test<std::uintmax_t>(); | ||
| test<std::uintmax_t>(); | ||
|
|
||
| test<void (*)(int)>(); | ||
| test<void*>(); | ||
| test<const void*>(); | ||
| test<int*>(); | ||
| test<const int*>(); | ||
|
|
||
| test<TriviallyCopyable>(); | ||
| test<PaddedTriviallyCopyable>(); | ||
| #ifndef __APPLE__ // Apple doesn't ship libatomic | ||
| /* | ||
| /* | ||
| These aren't going to be lock-free, | ||
| so some libatomic.a is necessary. | ||
| */ | ||
| test<WeirdTriviallyCopyable>(); | ||
| test<LargeTriviallyCopyable>(); | ||
| test<WeirdTriviallyCopyable>(); | ||
| test<LargeTriviallyCopyable>(); | ||
| #endif | ||
|
|
||
| #ifndef TEST_HAS_NO_THREADS | ||
| test<std::thread::id>(); | ||
| test<std::thread::id>(); | ||
| #endif | ||
| test<std::chrono::nanoseconds>(); | ||
| test<float>(); | ||
| test<std::chrono::nanoseconds>(); | ||
| test<float>(); | ||
|
|
||
| #if TEST_STD_VER >= 20 | ||
| test<std::atomic_signed_lock_free::value_type>(); | ||
| static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>); | ||
| static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>); | ||
| test<std::atomic_signed_lock_free::value_type>(); | ||
| static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>); | ||
| static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>); | ||
|
|
||
| test<std::atomic_unsigned_lock_free::value_type>(); | ||
| static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>); | ||
| static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>); | ||
| test<std::atomic_unsigned_lock_free::value_type>(); | ||
| static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>); | ||
| static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>); | ||
| /* | ||
| test<std::shared_ptr<int>>(); | ||
| */ | ||
| #endif | ||
|
|
||
| return 0; | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.