https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642

--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Miro Palmu from comment #11)
> I'm not sure if this is useful information but, using span with a view in a
> ranged-based for loop triggers false positive -Wdangling-referene on gcc
> 14.0.1 20240117 but not on gcc 13.2.
> 
> // On godbold: https://godbolt.org/z/x9jKh4MoW
> #include <ranges>
> #include <vector>
> #include <span>
> 
> int main() {
>     const auto vec = std::vector{ 1, 2, 3 };
>     const auto s = std::span<decltype(vec)::value_type const>{vec};
> 
>     // -Wwaring=dangling-reference on gcc 14.0.1 20240117 but not on gcc 13.2
>     for ([[maybe_unused]] auto _ : s | std::views::take(2)) { }
> 
>     // No warning
>     for ([[maybe_unused]] auto _ : vec | std::views::take(2)) { }
> 
>     // No warning
>     const auto s_view = s | std::views::take(2);
>     for ([[maybe_unused]] auto _ : s_view) { }
> }

This should be fixed now.  I'm going to expand Wdangling-reference17.C with
this test though.  Thanks.

Reply via email to