llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

std::ostream_iterator causes false "dangling pointer" positive

Open davidwin opened this issue 5 years ago • 1 comments

The following code should be considered correct (if you want to print the string "123"):

   std::vector<int> z { 1, 2, 3 };
   std::copy(z.begin(), z.end(), 
             std::ostream_iterator<int>(std::cout));

However, I get the following diagnostic

warning: passing a dangling pointer as argument [-Wlifetime]
             std::ostream_iterator<int>(std::cout));
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

note: it was never initialized here
             std::ostream_iterator<int>(std::cout));
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

See full repro case: https://godbolt.org/z/Rt3P6X

davidwin avatar Apr 20 '20 18:04 davidwin

Thanks you for taking the time to report this bug!

We will look into it.

mgehre avatar Apr 21 '20 06:04 mgehre