Updated error message. write variable name.

This commit is contained in:
Daniel Marjamäki 2015-05-02 16:55:17 +02:00
parent 4cbbd44d49
commit aab1d83075
2 changed files with 7 additions and 7 deletions

View File

@ -1627,5 +1627,5 @@ void CheckStl::readingEmptyStlContainer()
void CheckStl::readingEmptyStlContainerError(const Token *tok) void CheckStl::readingEmptyStlContainerError(const Token *tok)
{ {
reportError(tok, Severity::style, "reademptycontainer", "Reading from empty STL container", 0U, true); reportError(tok, Severity::style, "reademptycontainer", "Reading from empty STL container '" + (tok ? tok->str() : std::string("var")) + "'", 0U, true);
} }

View File

@ -2582,13 +2582,13 @@ private:
" std::string strValue = CMap[1]; \n" " std::string strValue = CMap[1]; \n"
" std::cout << strValue << CMap.size() << std::endl;\n" " std::cout << strValue << CMap.size() << std::endl;\n"
"}\n",true); "}\n",true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'CMap'\n", errout.str());
check("void f() {\n" check("void f() {\n"
" std::map<int,std::string> CMap;\n" " std::map<int,std::string> CMap;\n"
" std::string strValue = CMap[1];" " std::string strValue = CMap[1];"
"}\n",true); "}\n",true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'CMap'\n", errout.str());
check("void f() {\n" check("void f() {\n"
" std::map<int,std::string> CMap;\n" " std::map<int,std::string> CMap;\n"
@ -2605,7 +2605,7 @@ private:
" }\n" " }\n"
" return Vector;\n" " return Vector;\n"
"}\n",true); "}\n",true);
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Reading from empty STL container 'Vector'\n", errout.str());
check("f() {\n" check("f() {\n"
" try {\n" " try {\n"
@ -2656,21 +2656,21 @@ private:
" v.clear();\n" " v.clear();\n"
" int i = v.find(foobar);\n" " int i = v.find(foobar);\n"
"}", true); "}", true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'v'\n", errout.str());
check("void f() {\n" check("void f() {\n"
" std::map<int, std::string> CMap;\n" " std::map<int, std::string> CMap;\n"
" std::string strValue = CMap[1];\n" " std::string strValue = CMap[1];\n"
" std::string strValue2 = CMap[1];\n" " std::string strValue2 = CMap[1];\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'CMap'\n", errout.str());
// #4306 // #4306
check("void f(std::vector<int> v) {\n" check("void f(std::vector<int> v) {\n"
" v.clear();\n" " v.clear();\n"
" for(int i = 0; i < v.size(); i++) { cout << v[i]; }\n" " for(int i = 0; i < v.size(); i++) { cout << v[i]; }\n"
"}", true); "}", true);
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Reading from empty STL container 'v'\n", errout.str());
// #6663 // #6663
check("void foo() {\n" check("void foo() {\n"