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

            Bug ID: 111410
           Summary: Bogus Wdangling-reference warning with ranges pipe
                    expression in for loop
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

#include <iostream>
#include <vector>
#include <ranges>

int main()
{
  std::vector v{1, 2, 3, 4, 5};
  for (auto i : std::span{v} | std::views::take(1))
    std::cout << i << '\n';
}

GCC-trunk reports the following warning when the -Wall flag is used:

<source>:8:51: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
    8 |   for ( auto i : std::span{v} | std::views::take(1))
      |                                                   ^


https://godbolt.org/z/5jhnTTej9

Reply via email to