[gcc r17-816] libstdc++: Revert making ref_view<R> statically sized.
Tomasz Kaminski
tkaminsk@gcc.gnu.org
Tue May 26 16:18:59 GMT 2026
https://gcc.gnu.org/g:bd02a048e92a778c2d3fcc011b8a88e1ac6f8183
commit r17-816-gbd02a048e92a778c2d3fcc011b8a88e1ac6f8183
Author: Tomasz Kamiński <tkaminsk@redhat.com>
Date: Tue May 26 18:01:40 2026 +0200
libstdc++: Revert making ref_view<R> statically sized.
This patch reverts all changes except introduction of
ranges::__static_size from r17-810-g7239744d25dadf.
In addition to expected errors from breaking inplace_vector
preconditions, this lead to change in the return type of
define_static_array, when applied on (adapted) ref_view:
int x[10];
auto x = define_static_array(x | views::transform(...));
Type of x changed from span<const ...> to span<const ..., 10>,
due size being statically know.
This was considered beyond the scope of implementation freedom,
and we should wait for acceptance of P3928R0 instead.
libstdc++-v3/ChangeLog:
* include/std/ranges (ref_view::size()): Only call ranges::size(*_M_r).
(ref_view::empty): Only call ranges::empty(*_M_r).
* testsuite/23_containers/inplace_vector/cons/from_iota_neg.cc:
Except no errors from ref_view uses.
* testsuite/23_containers/inplace_vector/cons/from_range_neg.cc:
Likewise.
Diff:
---
libstdc++-v3/include/std/ranges | 18 ++----------------
.../23_containers/inplace_vector/cons/from_iota_neg.cc | 6 ++++--
.../inplace_vector/cons/from_range_neg.cc | 10 ++++++----
3 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 2f11cc2336f7..7d8b37f8c5cf 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -1382,25 +1382,11 @@ namespace views::__adaptor
constexpr bool
empty() const requires requires { ranges::empty(*_M_r); }
- {
-#if __cplusplus > 202302L
- if constexpr (__static_sized_range<_Range>)
- return ranges::__static_size<_Range>() == 0;
- else
-#endif
- return ranges::empty(*_M_r);
- }
+ { return ranges::empty(*_M_r); }
constexpr auto
size() const requires sized_range<_Range>
- {
-#if __cplusplus > 202302L
- if constexpr (__static_sized_range<_Range>)
- return ranges::__static_size<_Range>();
- else
-#endif
- return ranges::size(*_M_r);
- }
+ { return ranges::size(*_M_r); }
constexpr auto
data() const requires contiguous_range<_Range>
diff --git a/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_iota_neg.cc b/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_iota_neg.cc
index 6b66b5d97ed9..ae0b96175b7d 100644
--- a/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_iota_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_iota_neg.cc
@@ -33,12 +33,14 @@ test_all()
std::inplace_vector<int, 15> tr1(std::from_range, ref_view(m12));
std::inplace_vector<int, 10> tm2(std::from_range, m12); // { dg-error "(from here|expansion of)" }
- std::inplace_vector<int, 10> tr2(std::from_range, ref_view(m12)); // { dg-error "(from here|expansion of)" }
+ // ref_view is not statically sized due pointer dereference
+ std::inplace_vector<int, 10> tr2(std::from_range, ref_view(m12));
StaticIota<__int128, 0> mm;
std::inplace_vector<int, 10> tm3(std::from_range, mm); // { dg-error "(from here|expansion of)" }
- std::inplace_vector<int, 10> tr3(std::from_range, ref_view(mm)); // { dg-error "(from here|expansion of)" }
+ // ref_view is not statically sized due pointer dereference
+ std::inplace_vector<int, 10> tr3(std::from_range, ref_view(mm));
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
diff --git a/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_range_neg.cc b/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_range_neg.cc
index ea187761e5e7..48d5b4c56f59 100644
--- a/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_range_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/inplace_vector/cons/from_range_neg.cc
@@ -62,14 +62,16 @@ test_all()
test_one(a1); // { dg-error "from here" }
test_one(s1); // { dg-error "from here" }
- test_one(ref_view(a1)); // { dg-error "from here" }
- test_one(a5 | std::views::adjacent<5> | std::views::elements<0>); // { dg-error "from here" }
+ // ref_view is not statically sized due pointer dereference
+ test_one(ref_view(a1));
+ test_one(a5 | std::views::adjacent<7> | std::views::elements<0>);
test_one(s5 | std::views::adjacent<5> | std::views::elements<0>); // { dg-error "from here" }
test_five(a5); // { dg-error "from here" }
test_five(s5); // { dg-error "from here" }
- test_five(ref_view(a5)); // { dg-error "from here" }
- test_five(a7 | std::views::adjacent<3> | std::views::elements<0>); // { dg-error "from here" }
+ // ref_view is not statically sized due pointer dereference
+ test_five(ref_view(a5));
+ test_five(a7 | std::views::adjacent<3> | std::views::elements<0>);
test_five(s7 | std::views::adjacent<3> | std::views::elements<0>); // { dg-error "from here" }
}
More information about the Libstdc++-cvs
mailing list