[libcxx-commits] [PATCH] D143914: [libc++] Clean up pair's constructors and assignment operators
Hui via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 15 12:38:45 PST 2023
huixie90 added inline comments.
================
Comment at: libcxx/test/std/utilities/utility/pairs/pairs.pair/assign.pair_like_rv_const.pass.cpp:57
+
+ // Make sure it doesn't work for `ranges::subrange`, since it is called out explicitly.
+ {
----------------
tcanens wrote:
> ldionne wrote:
> > @tcanens @huixie90
> >
> > This behavior seems to be inconsistent with the non-const-qualified `operator=` from `pair-like`. For `operator=(PairLike)` (not `const`), it seems like we go through `subrange`'s `operator pair-like()`, which makes this work. But with `operator=(pair-like) const`, it looks like this conversion doesn't trigger and we end up not being able to perform the assignment. Does that match the LWG design intent?
> It doesn't trigger because `ConstAssignable` is not convertible from `int*`? Are the const/non-const cases actually different?
>
> IIRC the constraint is there to prevent bypassing the slicing check on subrange's `operator pair-like`.
speaking of `subrange`, I think it is worth adding more tests such as
```
Pair p = subrange1;
Pair p{subrange1};
auto p = static_cast<Pair>(subrange);
```
where the pair's constructor and subrange's conversion operator both can work.
(apparently subrange's conversion operator is more constrained than pair's constructor but I think that does not change anything?)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143914/new/
https://reviews.llvm.org/D143914
More information about the libcxx-commits
mailing list