Absolutely valid C++ code:
$ cat xxx.cpp struct S { void f(); }; S* g(); void h() { const auto& s = g(); if (s != nullptr) s->f(); }
all cppcheck messages are bogus:
$ cppcheck/2.8.0/bin/cppcheck xxx.cpp Checking xxx.cpp ... xxx.cpp:11:7: error: Using reference to dangling temporary. [danglingTempReference] if (s != nullptr) ^ xxx.cpp:10:17: note: Assigned to reference. const auto& s = g(); ^ xxx.cpp:11:7: note: Using reference to dangling temporary. if (s != nullptr) ^ xxx.cpp:12:5: error: Using reference to dangling temporary. [danglingTempReference] s->f(); ^ xxx.cpp:10:17: note: Assigned to reference. const auto& s = g(); ^ xxx.cpp:12:5: note: Using reference to dangling temporary. s->f(); ^
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11188
Log in to post a comment.
Absolutely valid C++ code:
all cppcheck messages are bogus:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11188