On Fri, 14 Mar 2025 at 17:16, Patrick Palka <ppa...@redhat.com> wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?  We could
> use a direct constexpr test for this from_range vector ctor code path,
> but that'll be easier once we make the __gnu_test range/iterators
> constexpr-friendly.  For now I just added an end-to-end test, which
> seems good to have too.

OK, thanks.

>
> -- >8 --
>
> A missing 'constexpr' in the non-forward (and non-sized) branch of
> vector's recently added from_range ctor was causing this constexpr
> example to be rejected with an obscure 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.
> ---
>  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 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<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());
>  }
> --
> 2.49.0.rc1.37.ge969bc8759
>

Reply via email to