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

Miro Palmu <miro.palmu at helsinki dot fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |miro.palmu at helsinki dot fi

--- Comment #11 from Miro Palmu <miro.palmu at helsinki dot fi> ---
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) { }
}

Reply via email to