From: Patrick Palka Date: Fri, 14 Mar 2025 20:10:35 +0000 (-0400) Subject: libstdc++: Missing 'constexpr' in vector's from_range ctor [PR119282] X-Git-Tag: basepoints/gcc-16~1490 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f03a8d7be9775312c50abdc99109aaf8641bda3;p=thirdparty%2Fgcc.git 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 --- diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 43d3cd1f171..9c75f64b6ef 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 09fd515edf1..231cb9d9934 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(); + 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()); }