]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Missing 'constexpr' in vector's from_range ctor [PR119282]
authorPatrick Palka <ppalka@redhat.com>
Fri, 14 Mar 2025 20:10:35 +0000 (16:10 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 14 Mar 2025 20:10:35 +0000 (16:10 -0400)
A missing 'constexpr' in the non-forward (and non-sized) branch of our
recently implemented vector from_range ctor was causing this valid example
to be rejected with a cryptic error.

PR libstdc++/119282

libstdc++-v3/ChangeLog:

* include/bits/stl_vector.h (vector::vector(from_range_t)): Add
missing 'constexpr' to local class _Clear.
* testsuite/std/ranges/conv/1.cc (test_pr119282): New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/stl_vector.h
libstdc++-v3/testsuite/std/ranges/conv/1.cc

index 43d3cd1f1714a7834b426594f3e008b094e3d09d..9c75f64b6ef828701f4975dda1b5615870823413 100644 (file)
@@ -778,7 +778,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
              // but will not destroy elements. This RAII type destroys them.
              struct _Clear
              {
-               ~_Clear() { if (_M_this) _M_this->clear(); }
+               constexpr ~_Clear() { if (_M_this) _M_this->clear(); }
                vector* _M_this;
              } __guard{this};
 
index 09fd515edf1b585089cc2316b0c90cf46925266e..231cb9d9934a4919cf6bf447f9378538dcb673d7 100644 (file)
@@ -466,6 +466,18 @@ test_composition()
   auto str = adaptor(" ");
 }
 
+constexpr bool
+test_pr119282()
+{
+  // PR libstdc++/119282
+  auto v = std::array{1, 2, 3}
+    | std::views::transform([](auto x) { return std::array{x}; })
+    | std::views::join
+    | std::ranges::to<std::vector>();
+  VERIFY( std::ranges::size(v) == 3 );
+  return true;
+}
+
 int main()
 {
   test_p1206r7_examples();
@@ -480,4 +492,5 @@ int main()
   test_constexpr();
   test_sfinae();
   test_composition();
+  static_assert(test_pr119282());
 }