Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

std::ostream_iterator causes false "dangling pointer" positive #93

Open
davidwin opened this issue Apr 20, 2020 · 1 comment
Open

std::ostream_iterator causes false "dangling pointer" positive #93

davidwin opened this issue Apr 20, 2020 · 1 comment

Comments

@davidwin
Copy link

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

@mgehre
Copy link
Owner

mgehre commented Apr 21, 2020

Thanks you for taking the time to report this bug!

We will look into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants