i want static analyzer warn me invalide rvalue dereference in following code.how can in clang or cppcheck?
#include <memory> using namespace std; unique_ptr<int> myfunc(void) { unique_ptr<int> a(new int(2)); return a; } int main() { const int& ra = *myfunc(); return 0; }
i cppcheck developer.
cppcheck has related checker std::string. instance, cppcheck warning code:
std::string hello(); unsigned int f() { const char *p = hello().c_str(); return 0; }
the warning is:
[2.cpp:4]: (error) dangerous usage of c_str(). value returned c_str() invalid after call.
it reported because returned std::string object deleted immediately. dereferencing pointer p anywhere after initialization ub.
i think great have warning unique_ptr code also.
if interested.. feel free this.
Comments
Post a Comment