-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement P3612R1 Harmonize Proxy-Reference Operations #5848
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
ec80052
4bed2e4
8c0a262
3ab0600
8f21bc7
5c9abf0
d81ed91
2418738
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ | |
| // P3323R1 Forbid atomic<cv T>, Specify atomic_ref<cv T> | ||
| // (for atomic<cv T>) | ||
| // P3503R3 Make Type-Erased Allocator Use In promise And packaged_task Consistent | ||
| // P3612R1 Harmonize Proxy-Reference Operations | ||
|
|
||
| // _HAS_CXX17 directly controls: | ||
| // P0005R4 not_fn() | ||
|
|
@@ -1512,7 +1513,16 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect | |
| #define _DEPRECATE_LOCALE_EMPTY | ||
| #endif // ^^^ warning disabled ^^^ | ||
|
|
||
| // next warning number: STL4049 | ||
| #if !defined(_SILENCE_VECTOR_BOOL_STATIC_REFERENCE_SWAP_DEPRECATION_WARNING) | ||
| #define _DEPRECATE_VECTOR_BOOL_STATIC_REFERENCE_SWAP \ | ||
| [[deprecated("warning STL4049: Static std::vector<bool>::swap(reference, reference) is deprecated. " \ | ||
|
||
| "Use non-member function swap(reference, reference) instead. You can define " \ | ||
| "_SILENCE_VECTOR_BOOL_STATIC_REFERENCE_SWAP_DEPRECATION_WARNING to suppress this warning.")]] | ||
| #else // ^^^ warning enabled / warning disabled vvv | ||
| #define _DEPRECATE_VECTOR_BOOL_STATIC_REFERENCE_SWAP | ||
| #endif // ^^^ warning disabled ^^^ | ||
|
|
||
| // next warning number: STL4050 | ||
|
|
||
| // next error number: STL1013 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,21 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| // This test was extended with functionality needed for | ||
| // P3612R1: Harmonize Proxy-Reference Operations | ||
|
|
||
| #include <algorithm> | ||
| #include <bitset> | ||
| #include <cassert> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| static const auto is_true = [](bool b) { return b; }; | ||
| static const auto is_false = [](bool b) { return !b; }; | ||
|
|
||
| int main() { | ||
| void check_values_match() { | ||
|
Contributor
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. I think we should also test the functionality in constant evaluation since C++20. E.g. we can mark this function #if _HAS_CXX20
#define CONSTEXPR20
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20
#define CONSEXPR20 inline
#endif // ^^^ !_HAS_CXX20 ^^^And then write check_values_match();
#if _HAS_CXX20
static_assert(check_values_match());
#endif // _HAS_CXX20Same for some other functions.
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. Understood; I tried to fix your comments, and a new issue surfaced: This could be solved naturally by adding I can look into it, but I need some guidance or precedent for adding
Contributor
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.
We can use #if _HAS_CXX20 && !_HAS_CXX23
if (!is_constant_evaluated())
#endif // _HAS_CXX20 && !_HAS_CXX23
{
/* test code for bitset<N>::reference */
}
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. I see your point. Nevertheless, could you please clarify what the issue would be with my suggestion (replacing about a dozen instances of Is it purely for maximal standards conformance? Or is constexpr part of ABI?
Contributor
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.
I guess the issue is that the standard explicitly forbids adding extra constexpr to functions ([constexpr.functions]).
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. Well, other changes introduced by this PR violate [constexpr.functions] as well, don't they? e.g. the change to Some degree of standards violation seems unavoidable when changes are backported... I don't mean to disagree, I'm just trying to get the correct mental model to simplify future contributions.
Contributor
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.
I'm not a language lawyer, but
I agree, but about a dozen explicit standard violations seems a bit excessive to me.
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. Understood.
Contributor
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. Implementing @frederick-vs-ja’s suggestion seems correct to me, but I’m not a maintainer.
Contributor
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.
I personally want to leave addition of |
||
| vector<bool> x(100, false); | ||
| vector<bool> y(100, true); | ||
|
|
||
|
|
@@ -27,3 +32,50 @@ int main() { | |
| assert(!y[34]); | ||
| assert(all_of(y.begin() + 35, y.end(), is_true)); | ||
| } | ||
|
|
||
| template <typename T> | ||
| void check_P3612(T& collection) { | ||
|
|
||
| auto ref0 = collection[0]; | ||
| auto const ref1 = collection[1]; | ||
|
|
||
| // assignments from bool | ||
| ref0 = true; | ||
| ref1 = false; | ||
| // assignments from reference | ||
| ref0 = ref1; | ||
| ref1 = ref0; | ||
|
|
||
| collection[0] = true; | ||
| collection[1] = false; | ||
|
|
||
| swap(collection[0], collection[1]); // swap(reference, reference) | ||
| assert(!collection[0]); | ||
|
|
||
| bool b = true; | ||
| swap(collection[0], b); // swap(reference, bool) | ||
| assert(collection[0]); | ||
|
|
||
| swap(b, collection[0]); // swap(bool, reference) | ||
| assert(!collection[0]); | ||
| } | ||
|
|
||
| template <typename T> | ||
| constexpr bool has_noexcept_copy_ctor = noexcept(T(std::declval<const T&>())); | ||
|
|
||
| int main() { | ||
| check_values_match(); | ||
|
|
||
|
|
||
| constexpr size_t N = 10; | ||
| vector<bool> vector(N); | ||
| bitset<N> bitset(0); | ||
|
|
||
| check_P3612(vector); | ||
| check_P3612(bitset); | ||
|
|
||
| static_assert(std::is_nothrow_copy_constructible_v<decltype(vector)::reference>, ""); | ||
| static_assert(std::is_nothrow_copy_constructible_v<decltype(bitset)::reference>, ""); | ||
| static_assert(has_noexcept_copy_ctor<decltype(vector)::reference>, ""); | ||
| static_assert(has_noexcept_copy_ctor<decltype(bitset)::reference>, ""); | ||
| } | ||
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.
Parameter name is meaningless here.