cppcheck: commit 62702a6
built with: make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes
$ cppcheck main.cpp
Checking main.cpp ...
main.cpp:19:13: error: Using iterator to local container 'm' to temporary. [danglingTemporaryLifetime]
auto it = a.m.find(2);
^
main.cpp:19:16: note: Iterator to container is created here.
auto it = a.m.find(2);
^
main.cpp:4:24: note: Variable created here.
std::map<int, int> m{{1, 1}, {2, 2}, {3, 3}};
^
main.cpp:19:13: note: Using iterator to local container 'm' to temporary.
auto it = a.m.find(2);
^
The error disappears if you remove the Base struct, it also goes away if you just remove the override keyword. P.ossibly related to False positive: [returnTempReference]
Last edit: Andreas Grob 2020-07-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
cppcheck: commit 62702a6
built with: make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes
The error disappears if you remove the Base struct, it also goes away if you just remove the override keyword. P.ossibly related to False positive: [returnTempReference]
Last edit: Andreas Grob 2020-07-17
Thanks! I have created ticket https://trac.cppcheck.net/ticket/9813
Fixed for me in 48a6852.