https://gcc.gnu.org/g:2f03a8d7be9775312c50abdc99109aaf8641bda3

commit r15-8063-g2f03a8d7be9775312c50abdc99109aaf8641bda3
Author: Patrick Palka <ppa...@redhat.com>
Date:   Fri Mar 14 16:10:35 2025 -0400

    libstdc++: Missing 'constexpr' in vector's from_range ctor [PR119282]
    
    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 <jwak...@redhat.com>

Diff:
---
 libstdc++-v3/include/bits/stl_vector.h      |  2 +-
 libstdc++-v3/testsuite/std/ranges/conv/1.cc | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_vector.h 
b/libstdc++-v3/include/bits/stl_vector.h
index 43d3cd1f1714..9c75f64b6ef8 100644
--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -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};
 
diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc 
b/libstdc++-v3/testsuite/std/ranges/conv/1.cc
index 09fd515edf1b..231cb9d9934a 100644
--- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc
@@ -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());
 }

Reply via email to