Thanks a lot for your awesome project. I think I've found a false positive for danglingTemporaryLifetime warning:
#include<iostream>#include<vector>std::vector<int>ints={0,1,2,3};intmain(){auto*ptr=&ints;if(rand()/2==0){ptr=&ints;}for(autoit=ptr->cbegin();it!=ptr->cend();++it){// Using iterator to temporary.std::cout<<*it<<"\n";// Using iterator to temporary.}return0;}
Removing the if block removes the warning. Changing the condition to something more predictable (e.g. true) removes the warning. I'm not sure why such code should trigger a warning.
Thanks again for your project.
Last edit: Julien 2022-01-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
Thanks a lot for your awesome project. I think I've found a false positive for
danglingTemporaryLifetime
warning:Removing the
if
block removes the warning. Changing the condition to something more predictable (e.g.true
) removes the warning. I'm not sure why such code should trigger a warning.Thanks again for your project.
Last edit: Julien 2022-01-04
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10683