[Bug libstdc++/101091] std::views::take and std::views::drop are overconstrained

2021-06-16 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101091

Patrick Palka  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 CC||ppalka at gcc dot gnu.org
 Status|UNCONFIRMED |RESOLVED

--- Comment #2 from Patrick Palka  ---
Thanks for the bug report.  This regression is already fixed for GCC 11.2 and
12, see PR100558.

*** This bug has been marked as a duplicate of bug 100558 ***

[Bug libstdc++/101091] std::views::take and std::views::drop are overconstrained

2021-06-16 Thread j.galecki11 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101091

--- Comment #1 from Jakub Gałecki  ---
Consider the following example: https://godbolt.org/z/YYzqWaM9G

#include 
#include 
#include 

void copy_drop_n1(const std::vector& src, std::vector& dest,
  std::size_t n) {  // size_t - narrowing conversion
  std::ranges::copy(src | std::views::drop(n), begin(dest) + n);
}

void copy_drop_n2(const std::vector& src, std::vector& dest,
  std::ptrdiff_t n) {  // ptrdiff_t
  std::ranges::copy(src | std::views::drop(n), begin(dest) + n);
}

As per the standard [range.take.overview]:
The name views​::​take denotes a range adaptor object ([range.adaptor.object]).
Let E and F be expressions, let T be remove_­cvref_­t, and let D
be range_­difference_­t. If decltype((F)) does not model
convertible_­to, views​::​take(E, F) is ill-formed. Otherwise, the
expression views​::​take(E, F) is expression-equivalent to [...]

The example above should therefore compile for size_t as well as ptrdiff_t,
since size_t is convertible to ptrdiff_t. This is a regression from libstdc++
version 10.x, where both functions compile.