Correct me If I am wrong but this is probably false positive.
#include <map> #include <gmock/gmock.h> #include <gtest/gtest.h> typedef std::map<char, const char*> map_test; struct Object { Object() : map() {} map_test map; }; map_test func() { return map_test(); } TEST(test, test) { Object test_object; map_test& standard = test_object.map; EXPECT_STREQ("some_value", standard['c']); }
Cppcheck: style/constVariable: Variable 'standard' can be declared with const
Adding const to "standard" variable does not compile.
Using --library=googletest in cppcheck arguments.
Thanks! I think this has been fixed. I can reproduce with cppcheck-2.0 but not with cppcheck HEAD.
danielm@edge:~/cppcheck$ ./cppcheck --library=googletest fp1.cpp --enable=style Checking fp1.cpp ... danielm@edge:~/cppcheck$ ../.cppcheck/cppcheck-2.0 --library=googletest fp1.cpp --enable=style Checking fp1.cpp ... fp1.cpp:15:14: style: Variable 'standard' can be declared with const [constVariable] map_test& standard = test_object.map; ^
Thanks for quick response! I can reproduce this with cppcheck-2.1
Log in to post a comment.
Correct me If I am wrong but this is probably false positive.
Cppcheck:
style/constVariable: Variable 'standard' can be declared with const
Adding const to "standard" variable does not compile.
Using --library=googletest in cppcheck arguments.
Last edit: biwipo4118 2020-09-29
Thanks! I think this has been fixed. I can reproduce with cppcheck-2.0 but not with cppcheck HEAD.
Thanks for quick response!
I can reproduce this with cppcheck-2.1