This commit is contained in:
Sébastien Debrard 2011-01-30 13:25:54 +01:00
commit f2082a47bc
22 changed files with 478 additions and 276 deletions

View File

@ -88,7 +88,7 @@ static BOOL MyIsDirectory(std::string path)
return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY); return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
#else #else
// See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx // See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
return PathIsDirectory(path.c_str()); return PathIsDirectory(path.c_str());
#endif #endif
} }

View File

@ -921,7 +921,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
} }
if (tok2->varId() == varid || if (tok2->varId() == varid ||
tok2->str() == ":" || tok2->str() == "{") tok2->str() == ":" || tok2->str() == "{" || tok2->str() == "}")
{ {
break; break;
} }
@ -2727,8 +2727,8 @@ void CheckMemoryLeakInClass::check()
// known class? // known class?
else if (var->type()) else if (var->type())
{ {
// not derived and no constructor? // not derived?
if (var->type()->derivedFrom.empty() && var->type()->numConstructors == 0) if (var->type()->derivedFrom.empty())
{ {
if (var->isPrivate()) if (var->isPrivate())
checkPublicFunctions(scope, var->nameToken()); checkPublicFunctions(scope, var->nameToken());

View File

@ -69,6 +69,15 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
functionNames1.insert("strndup"); functionNames1.insert("strndup");
functionNames1.insert("strlen"); functionNames1.insert("strlen");
functionNames1.insert("strstr"); functionNames1.insert("strstr");
functionNames1.insert("fclose");
functionNames1.insert("feof");
functionNames1.insert("fread");
functionNames1.insert("fwrite");
functionNames1.insert("fseek");
functionNames1.insert("ftell");
functionNames1.insert("fgetpos");
functionNames1.insert("fsetpos");
functionNames1.insert("rewind");
} }
// standard functions that dereference second parameter.. // standard functions that dereference second parameter..

View File

@ -1040,6 +1040,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
// Re-constitute the configuration after sorting the defines // Re-constitute the configuration after sorting the defines
defs.sort(); defs.sort();
defs.unique();
*it = join(defs, ';'); *it = join(defs, ';');
} }

View File

@ -2083,7 +2083,7 @@ bool Tokenizer::tokenize(std::istream &code,
} }
// remove inline SQL (Oracle PRO*C). Ticket: #1959 // replace inline SQL with "asm()" (Oracle PRO*C). Ticket: #1959
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::simpleMatch(tok, "EXEC SQL")) if (Token::simpleMatch(tok, "EXEC SQL"))
@ -2123,6 +2123,9 @@ bool Tokenizer::tokenize(std::istream &code,
} }
} }
// remove some unhandled macros in global scope
removeMacrosInGlobalScope();
// specify array size.. // specify array size..
arraySize(); arraySize();
@ -4383,6 +4386,23 @@ bool Tokenizer::simplifyTokenList()
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void Tokenizer::removeMacrosInGlobalScope()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "(")
{
tok = tok->link();
if (Token::Match(tok, ") %type% {") && tok->strAt(1) != "const")
tok->deleteNext();
}
if (tok->str() == "{")
tok = tok->link();
}
}
//---------------------------------------------------------------------------
void Tokenizer::removeRedundantAssignment() void Tokenizer::removeRedundantAssignment()
{ {
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())

View File

@ -186,6 +186,9 @@ public:
/** Simplify labels */ /** Simplify labels */
void labels(); void labels();
/** Remove macros in global scope */
void removeMacrosInGlobalScope();
/** Remove redundant assignment */ /** Remove redundant assignment */
void removeRedundantAssignment(); void removeRedundantAssignment();

View File

@ -561,8 +561,8 @@ private:
" char str[5];\n" " char str[5];\n"
" memclr( 10, str ); // ERROR\n" " memclr( 10, str ); // ERROR\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (possible error) Array index out of bounds\n",
ASSERT_EQUALS("", errout.str()); // current result "", errout.str());
// This is not an error // This is not an error
check("static void memclr( char *data, int size )\n" check("static void memclr( char *data, int size )\n"
@ -610,8 +610,8 @@ private:
"{\n" "{\n"
" memclr(abc->str);\n" " memclr(abc->str);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:8]: (possible error) Array index out of bounds\n",
TODO_ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:8]: (possible error) Array index out of bounds\n", errout.str()); "", errout.str());
} }
@ -795,8 +795,7 @@ private:
" i+=1;\n" " i+=1;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); // Catch changes TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str());
} }
void array_index_19() void array_index_19()
@ -1001,8 +1000,7 @@ private:
" int *ip = &i[1];\n" " int *ip = &i[1];\n"
" ip[-10] = 1;\n" " ip[-10] = 1;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds\n", errout.str());
} }
void array_index_29() void array_index_29()
@ -1015,8 +1013,7 @@ private:
" int *ii = &i[-5];" " int *ii = &i[-5];"
" ii[10] = 0;" " ii[10] = 0;"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds\n", errout.str());
} }
void array_index_30() void array_index_30()
@ -1133,7 +1130,7 @@ private:
" char a[10][10][10];\n" " char a[10][10][10];\n"
" a[2*3][4*3][2] = 'a';\n" " a[2*3][4*3][2] = 'a';\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' index a[6][12][2] out of bounds\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' index a[6][12][2] out of bounds\n", "", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"
@ -1201,8 +1198,7 @@ private:
" };\n" " };\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds\n", errout.str());
} }
void array_index_calculation() void array_index_calculation()
@ -1295,8 +1291,7 @@ private:
" val[i+1] = val[i];\n" " val[i+1] = val[i];\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); // catch changes TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array 'val[5]' index -1 out of bounds\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array 'val[5]' index -1 out of bounds\n", errout.str());
} }
@ -1562,8 +1557,7 @@ private:
" char s[3];\n" " char s[3];\n"
" f1(s,3);\n" " f1(s,3);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Buffer access out-of-bounds\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Buffer access out-of-bounds\n", "", errout.str());
ASSERT_EQUALS("", errout.str());
check("void f1(char *s,int size)\n" check("void f1(char *s,int size)\n"
"{\n" "{\n"
@ -1999,8 +1993,7 @@ private:
" char buf[3];\n" " char buf[3];\n"
" sprintf(buf, \"%s\", condition ? \"11\" : \"222\");\n" " sprintf(buf, \"%s\", condition ? \"11\" : \"222\");\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); // catch changes TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
} }
void sprintf7() void sprintf7()
@ -2224,8 +2217,7 @@ private:
" char a[5], b[50];\n" " char a[5], b[50];\n"
" memchr(a, b, 10);\n" " memchr(a, b, 10);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", "", errout.str());
ASSERT_EQUALS("", errout.str());
} }
// ticket #2121 - buffer access out of bounds when using uint32_t // ticket #2121 - buffer access out of bounds when using uint32_t
@ -2466,7 +2458,7 @@ private:
ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%08ld", intAsParameter)); ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%08ld", intAsParameter));
ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%.2d", intAsParameter)); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%.2d", intAsParameter));
ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%08.2d", intAsParameter)); ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%08.2d", intAsParameter));
TODO_ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%x", intAsParameter)); TODO_ASSERT_EQUALS(5, 2, CheckBufferOverrun::countSprintfLength("%x", intAsParameter));
ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%4x", intAsParameter)); ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%4x", intAsParameter));
ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%5x", intAsParameter)); ASSERT_EQUALS(6, CheckBufferOverrun::countSprintfLength("%5x", intAsParameter));
ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%.4x", intAsParameter)); ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%.4x", intAsParameter));
@ -2478,17 +2470,17 @@ private:
Token floatTok(0); Token floatTok(0);
floatTok.str("1.12345f"); floatTok.str("1.12345f");
floatAsParameter.push_back(&floatTok); floatAsParameter.push_back(&floatTok);
TODO_ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter)); TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter));
ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%8.2f", floatAsParameter)); ASSERT_EQUALS(9, CheckBufferOverrun::countSprintfLength("%8.2f", floatAsParameter));
TODO_ASSERT_EQUALS(5, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter)); TODO_ASSERT_EQUALS(5, 3, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter));
std::list<const Token*> floatAsParameter2; std::list<const Token*> floatAsParameter2;
Token floatTok2(0); Token floatTok2(0);
floatTok2.str("100.12345f"); floatTok2.str("100.12345f");
floatAsParameter2.push_back(&floatTok2); floatAsParameter2.push_back(&floatTok2);
TODO_ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter2)); TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength("%2.2f", floatAsParameter2));
TODO_ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter)); TODO_ASSERT_EQUALS(7, 3, CheckBufferOverrun::countSprintfLength("%.2f", floatAsParameter));
TODO_ASSERT_EQUALS(7, CheckBufferOverrun::countSprintfLength("%4.2f", floatAsParameter)); TODO_ASSERT_EQUALS(7, 5, CheckBufferOverrun::countSprintfLength("%4.2f", floatAsParameter));
std::list<const Token*> multipleParams; std::list<const Token*> multipleParams;
multipleParams.push_back(&strTok); multipleParams.push_back(&strTok);

View File

@ -1498,7 +1498,8 @@ private:
"public:\n" "public:\n"
" ~B() { int a; }\n" " ~B() { int a; }\n"
"};\n"); "};\n");
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class A which is inherited by class B does not have a virtual destructor\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class A which is inherited by class B does not have a virtual destructor\n",
"", errout.str());
} }
void virtualDestructorTemplate() void virtualDestructorTemplate()
@ -4303,7 +4304,8 @@ private:
"std::vector<std::string> m_strVec;\n" "std::vector<std::string> m_strVec;\n"
"};\n" "};\n"
); );
TODO_ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::strGetSize' can be const.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (information) Technically the member function 'A::strGetSize' can be const.\n",
"", errout.str());
} }
void const26() // ticket #1847 void const26() // ticket #1847
@ -4625,8 +4627,8 @@ private:
"}\n" "}\n"
"using namespace N;\n" "using namespace N;\n"
"int Base::getResourceName() { return var; }\n"); "int Base::getResourceName() { return var; }\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (information) Technically the member function 'N::Base::getResourceName' can be const.\n",
TODO_ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (information) Technically the member function 'N::Base::getResourceName' can be const.\n", errout.str()); "", errout.str());
} }
void const36() // ticket #2003 void const36() // ticket #2003
@ -5076,7 +5078,8 @@ private:
" A(){}\n" " A(){}\n"
" unsigned int GetVecSize() {return m_v.size();}\n" " unsigned int GetVecSize() {return m_v.size();}\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:7]: (information) Technically the member function 'A::GetVecSize' can be const.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:7]: (information) Technically the member function 'A::GetVecSize' can be const.\n",
"", errout.str());
} }
void constVirtualFunc() void constVirtualFunc()

View File

@ -74,8 +74,8 @@ private:
" unsigned int uvar = 2;\n" " unsigned int uvar = 2;\n"
" return ivar / uvar;\n" " return ivar / uvar;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
} }
void division2() void division2()
@ -86,8 +86,8 @@ private:
" unsigned int uvar = 2;\n" " unsigned int uvar = 2;\n"
" return uvar / ivar;\n" " return uvar / ivar;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Division with signed and unsigned operators\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
} }
void division4() void division4()
@ -166,8 +166,8 @@ private:
" unsigned int c = a / b;\n" " unsigned int c = a / b;\n"
" }\n" " }\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("unsigned division",
TODO_ASSERT_EQUALS("unsigned division", errout.str()); "", errout.str());
check("void a(int i) { }\n" check("void a(int i) { }\n"
"int foo( unsigned int sz )\n" "int foo( unsigned int sz )\n"
@ -186,8 +186,8 @@ private:
" unsigned long uvar = 2;\n" " unsigned long uvar = 2;\n"
" return ivar / uvar;\n" " return ivar / uvar;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("unsigned division",
TODO_ASSERT_EQUALS("unsigned division", errout.str()); "", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"
@ -195,8 +195,8 @@ private:
" unsigned long long uvar = 2;\n" " unsigned long long uvar = 2;\n"
" return ivar / uvar;\n" " return ivar / uvar;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("unsigned division",
TODO_ASSERT_EQUALS("unsigned division", errout.str()); "", errout.str());
} }
}; };

View File

@ -403,8 +403,8 @@ private:
ASSERT_EQUALS(";;dealloc;", getcode("char *s; free(reinterpret_cast<void *>(s));", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; free(reinterpret_cast<void *>(s));", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete s;", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete s;", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (s);", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (s);", "s"));
ASSERT_EQUALS(";;;", getcode("char *s; delete (void *)(s);", "s")); // current result.. TODO_ASSERT_EQUALS(";;dealloc;",
TODO_ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (void *)(s);", "s")); // ..wanted result ";;;", getcode("char *s; delete (void *)(s);", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] s;", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] s;", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] (s);", "s")); ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] (s);", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(fclose(p));", "p")); ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(fclose(p));", "p"));
@ -453,7 +453,8 @@ private:
// Since we don't check how the return value is used we must bail out // Since we don't check how the return value is used we must bail out
ASSERT_EQUALS("", getcode("char *s; int ret = asprintf(&s, \"xyz\");", "s")); ASSERT_EQUALS("", getcode("char *s; int ret = asprintf(&s, \"xyz\");", "s"));
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; int ret; ret=asprintf(&s, \"xyz\"); if (ret==-1) return;", "s")); TODO_ASSERT_EQUALS(";;alloc;",
"", getcode("char *s; int ret; ret=asprintf(&s, \"xyz\"); if (ret==-1) return;", "s"));
// use.. // use..
ASSERT_EQUALS(";;use;", getcode("char *s; a(s);", "s")); ASSERT_EQUALS(";;use;", getcode("char *s; a(s);", "s"));
@ -695,10 +696,8 @@ private:
ASSERT_EQUALS("; use ;", simplifycode("; while1 { if { dealloc ; return ; } if { if { continue ; } } }")); ASSERT_EQUALS("; use ;", simplifycode("; while1 { if { dealloc ; return ; } if { if { continue ; } } }"));
// scope.. // scope..
// current result - ok TODO_ASSERT_EQUALS("; assign ; if alloc ; }",
ASSERT_EQUALS("; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }")); "; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
// wanted result - better
TODO_ASSERT_EQUALS("; assign ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
// callfunc.. // callfunc..
ASSERT_EQUALS("; callfunc ; }", simplifycode(";callfunc;}")); ASSERT_EQUALS("; callfunc ; }", simplifycode(";callfunc;}"));
@ -713,8 +712,10 @@ private:
ASSERT_EQUALS(";", simplifycode("; if { alloc; exit; }")); ASSERT_EQUALS(";", simplifycode("; if { alloc; exit; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if { use; exit; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if { use; exit; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }"));
TODO_ASSERT_EQUALS(";", simplifycode("; alloc ; if(var) { exit; }")); TODO_ASSERT_EQUALS(";",
TODO_ASSERT_EQUALS(";\n; alloc ;", simplifycode("; alloc ; ifv { exit; }")); "; if(var) exit ;", simplifycode("; alloc ; if(var) { exit; }"));
TODO_ASSERT_EQUALS(";\n; alloc ;",
"; alloc ; ifv exit ;", simplifycode("; alloc ; ifv { exit; }"));
// try-catch // try-catch
ASSERT_EQUALS("; }", simplifycode("; try ; catch exit ; }")); ASSERT_EQUALS("; }", simplifycode("; try ; catch exit ; }"));
@ -808,8 +809,8 @@ private:
ASSERT_EQUALS(2, dofindleak(";alloc;\n if assign;\n dealloc;")); ASSERT_EQUALS(2, dofindleak(";alloc;\n if assign;\n dealloc;"));
// loop.. // loop..
TODO_ASSERT_EQUALS(1, dofindleak("; loop { alloc ; if break; dealloc ; }")); TODO_ASSERT_EQUALS(1, notfound, dofindleak("; loop { alloc ; if break; dealloc ; }"));
TODO_ASSERT_EQUALS(1, dofindleak("; loop { alloc ; if continue; dealloc ; }")); TODO_ASSERT_EQUALS(1, notfound, dofindleak("; loop { alloc ; if continue; dealloc ; }"));
ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;")); ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;"));
ASSERT_EQUALS(1, dofindleak("; loop alloc ;")); ASSERT_EQUALS(1, dofindleak("; loop alloc ;"));
ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;")); ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;"));
@ -1132,13 +1133,11 @@ private:
" }\n" " }\n"
" delete [] x;\n" " delete [] x;\n"
"}\n", true); "}\n", true);
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: x\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: x\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
} }
void forwhile5() void forwhile5()
{ {
check("void f(const char **a)\n" check("void f(const char **a)\n"
@ -1187,8 +1186,10 @@ private:
"\n" "\n"
" return a;\n" " return a;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: a\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: a\n",
ASSERT_EQUALS("[test.cpp:8]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n", errout.str());
"[test.cpp:8]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n",
errout.str());
} }
@ -1478,8 +1479,8 @@ private:
" char *p = new char[100];\n" " char *p = new char[100];\n"
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
} }
@ -1880,8 +1881,8 @@ private:
" char *p;\n" " char *p;\n"
" foo(&p);\n" " foo(&p);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), errout.str()); TODO_ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"),
ASSERT_EQUALS("", errout.str()); "", errout.str());
check("void foo(char **str)\n" check("void foo(char **str)\n"
"{\n" "{\n"
@ -2083,8 +2084,10 @@ private:
" free(a);\n" " free(a);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n",
ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n", errout.str());
"[test.cpp:4]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n",
errout.str());
} }
void realloc5() void realloc5()
@ -2296,8 +2299,8 @@ private:
" free(str);\n" " free(str);\n"
" char c = *str;\n" " char c = *str;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
@ -3165,6 +3168,7 @@ private:
TEST_CASE(class18); TEST_CASE(class18);
TEST_CASE(class19); // ticket #2219 TEST_CASE(class19); // ticket #2219
TEST_CASE(class20); TEST_CASE(class20);
TEST_CASE(class21); // ticket #2517
TEST_CASE(staticvar); TEST_CASE(staticvar);
@ -4018,6 +4022,45 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: Fred::str1\n", errout.str()); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: Fred::str1\n", errout.str());
} }
void class21() // ticket #2517
{
check("struct B { };\n"
"struct C\n"
"{\n"
" B * b;\n"
" C(B * x) : b(x) { }\n"
"};\n"
"class A\n"
"{\n"
" B *b;\n"
" C *c;\n"
"public:\n"
" A() : b(new B()), c(new C(b)) { }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: A::b\n"
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
check("struct B { };\n"
"struct C\n"
"{\n"
" B * b;\n"
" C(B * x) : b(x) { }\n"
"};\n"
"class A\n"
"{\n"
" B *b;\n"
" C *c;\n"
"public:\n"
" A()\n"
" {\n"
" b = new B();\n"
" c = new C(b);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: A::b\n"
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
}
void staticvar() void staticvar()
{ {
check("class A\n" check("class A\n"
@ -4144,8 +4187,8 @@ private:
"private:\n" "private:\n"
" char *s;\n" " char *s;\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("publicAllocation",
TODO_ASSERT_EQUALS("publicAllocation", errout.str()); "", errout.str());
} }
void func2() void func2()

View File

@ -464,8 +464,8 @@ private:
" p = new FooCar;\n" " p = new FooCar;\n"
" p->abcd();\n" " p->abcd();\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
check("static void foo()\n" check("static void foo()\n"
"{\n" "{\n"
@ -707,8 +707,8 @@ private:
" argv32[i] = 0;\n" " argv32[i] = 0;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("error",
TODO_ASSERT_EQUALS("error", errout.str()); "", errout.str());
} }
void nullpointer7() void nullpointer7()

View File

@ -166,8 +166,8 @@ private:
" const char i = index(var, 0);\n" " const char i = index(var, 0);\n"
" return i;\n" " return i;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n",
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", errout.str()); "", errout.str());
} }
void test_qt_index() void test_qt_index()

View File

@ -1662,8 +1662,9 @@ private:
"}\n" "}\n"
); );
TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0" TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0"
" bytes of \"p\". Second and third arguments might be inverted.\n", errout.str()); " bytes of \"p\". Second and third arguments might be inverted.\n",
ASSERT_EQUALS("", errout.str());
"", errout.str());
} }
void sizeofForArrayParameter() void sizeofForArrayParameter()

View File

@ -295,7 +295,8 @@ private:
" std::cout << k << std::endl;\n" " std::cout << k << std::endl;\n"
" return 0;\n" " return 0;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("",
"[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
} }
void testiterator() void testiterator()

View File

@ -173,6 +173,7 @@ private:
TEST_CASE(endifsemicolon); TEST_CASE(endifsemicolon);
TEST_CASE(missing_doublequote); TEST_CASE(missing_doublequote);
TEST_CASE(handle_error); TEST_CASE(handle_error);
TEST_CASE(dup_defines);
TEST_CASE(unicodeInCode); TEST_CASE(unicodeInCode);
TEST_CASE(unicodeInComment); TEST_CASE(unicodeInComment);
@ -428,8 +429,8 @@ private:
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Make sure an error message is written.. // Make sure an error message is written..
ASSERT_EQUALS("", errout.str()); // no change? TODO_ASSERT_EQUALS("[test.cpp:3]: this preprocessor condition is always true",
TODO_ASSERT_EQUALS("[test.cpp:3]: this preprocessor condition is always true", errout.str()); "", errout.str());
// Compare results.. // Compare results..
ASSERT_EQUALS("\n\n\n\n\n\n", actual[""]); ASSERT_EQUALS("\n\n\n\n\n\n", actual[""]);
@ -754,7 +755,7 @@ private:
ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "A<2")); ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "A<2"));
ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "A==2")); ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "A==2"));
ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "A<1")); ASSERT_EQUALS(false, Preprocessor::match_cfg_def(cfg, "A<1"));
TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def(cfg, "A>=1&&B<=A")); TODO_ASSERT_EQUALS(true, false, Preprocessor::match_cfg_def(cfg, "A>=1&&B<=A"));
} }
} }
@ -777,7 +778,8 @@ private:
// Compare results.. // Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size())); ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\n\n\nB\n\n", actual[""]); ASSERT_EQUALS("\n\n\nB\n\n", actual[""]);
TODO_ASSERT_EQUALS("\nA\n\n\n\n", actual["LIBVER=101"]); TODO_ASSERT_EQUALS("\nA\n\n\n\n",
"", actual["LIBVER=101"]);
} }
void if_cond2() void if_cond2()
@ -1008,8 +1010,7 @@ private:
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size())); TODO_ASSERT_EQUALS(2, 1, static_cast<unsigned int>(actual.size()));
TODO_ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\nfoo();\n\n", actual[""]); ASSERT_EQUALS("\nfoo();\n\n", actual[""]);
} }
} }
@ -1169,8 +1170,9 @@ private:
// the "defined(DEF_10) || defined(DEF_11)" are not handled correctly.. // the "defined(DEF_10) || defined(DEF_11)" are not handled correctly..
ASSERT_EQUALS("(debug) unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", errout.str()); ASSERT_EQUALS("(debug) unhandled configuration: defined(DEF_10)||defined(DEF_11)\n", errout.str());
TODO_ASSERT_EQUALS(2, actual.size()); TODO_ASSERT_EQUALS(2, 1, actual.size());
TODO_ASSERT_EQUALS("\na1;\n\n", actual["DEF_10"]); TODO_ASSERT_EQUALS("\na1;\n\n",
"", actual["DEF_10"]);
} }
@ -2311,8 +2313,8 @@ private:
// Compare results.. // Compare results..
ASSERT_EQUALS("\n\n\n\n", actual[""]); ASSERT_EQUALS("\n\n\n\n", actual[""]);
TODO_ASSERT_EQUALS(1, actual.size()); TODO_ASSERT_EQUALS(1,
ASSERT_EQUALS(2, (int)actual.size()); 2, actual.size());
} }
void define_ifndef2() void define_ifndef2()
@ -2380,6 +2382,48 @@ private:
ASSERT_EQUALS("char a[] = \"#endfile\";\nchar b[] = \"#endfile\";\n\n", actual[""]); ASSERT_EQUALS("char a[] = \"#endfile\";\nchar b[] = \"#endfile\";\n\n", actual[""]);
ASSERT_EQUALS(1, (int)actual.size()); ASSERT_EQUALS(1, (int)actual.size());
} }
void dup_defines()
{
const char filedata[] = "#ifdef A\n"
"#define B\n"
"#if defined(B) && defined(A)\n"
"a\n"
"#else\n"
"b\n"
"#endif\n"
"#endif\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
// B will always be defined if A is defined; the following test
// cases should be fixed whenever this other bug is fixed
TODO_ASSERT_EQUALS(2,
3, static_cast<unsigned int>(actual.size()));
if (actual.find("A") == actual.end())
{
ASSERT_EQUALS("A is checked", "failed");
}
else
{
ASSERT_EQUALS("A is checked", "A is checked");
}
if (actual.find("A;A;B") != actual.end())
{
ASSERT_EQUALS("A;A;B is NOT checked", "failed");
}
else
{
ASSERT_EQUALS("A;A;B is NOT checked", "A;A;B is NOT checked");
}
}
}; };
REGISTER_TEST(TestPreprocessor) REGISTER_TEST(TestPreprocessor)

View File

@ -698,8 +698,8 @@ private:
" if (c>0) { c++; }\n" " if (c>0) { c++; }\n"
" c++;\n" " c++;\n"
"}\n"; "}\n";
TODO_ASSERT_EQUALS("void f ( int & c ) { c = 3 ; { ; } ; }", tok(code)); TODO_ASSERT_EQUALS("void f ( int & c ) { c = 3 ; { ; } ; }",
ASSERT_EQUALS("void f ( int & c ) { c = 1 ; { c ++ ; } c ++ ; }", tok(code)); "void f ( int & c ) { c = 1 ; { c ++ ; } c ++ ; }", tok(code));
} }
@ -713,8 +713,8 @@ private:
" if (c>0) { ++c; }\n" " if (c>0) { ++c; }\n"
" ++c;\n" " ++c;\n"
"}\n"; "}\n";
TODO_ASSERT_EQUALS("void f ( int & c ) { c = 3 ; { ; } ; }", tok(code)); TODO_ASSERT_EQUALS("void f ( int & c ) { c = 3 ; { ; } ; }",
ASSERT_EQUALS("void f ( int & c ) { c = 1 ; { ++ c ; } ++ c ; }", tok(code)); "void f ( int & c ) { c = 1 ; { ++ c ; } ++ c ; }", tok(code));
} }
{ {
@ -1633,14 +1633,22 @@ private:
" return 0;\n" " return 0;\n"
"}\n"; "}\n";
const std::string expected("; " const std::string wanted("; "
"int main ( ) { " "int main ( ) { "
"std :: vector < int > v ; " "std :: vector < int > v ; "
"v . push_back ( 4 ) ; " "v . push_back ( 4 ) ; "
"return 0 ; " "return 0 ; "
"}"); "}");
TODO_ASSERT_EQUALS(expected, sizeof_(code)); const std::string current("; "
"int main ( ) { "
"ABC < int > :: type v ; "
"v . push_back ( 4 ) ; "
"return 0 ; "
"}"
);
TODO_ASSERT_EQUALS(wanted, current, sizeof_(code));
} }
{ {
@ -1855,14 +1863,18 @@ private:
" return 0;\n" " return 0;\n"
"}\n"; "}\n";
// The expected result.. const std::string wanted("; "
const std::string expected("; "
"; " "; "
"int main ( ) { b<2> ( ) ; return 0 ; } " "int main ( ) { b<2> ( ) ; return 0 ; } "
"void b<2> ( ) { a<2> ( ) ; } " "void b<2> ( ) { a<2> ( ) ; } "
"void a<2> ( ) { }"); "void a<2> ( ) { }");
TODO_ASSERT_EQUALS(expected, sizeof_(code)); const std::string current("; "
"int main ( ) { b<2> ( ) ; return 0 ; } "
"void b<2> ( ) { a < 2 > ( ) ; }"
);
TODO_ASSERT_EQUALS(wanted, current, sizeof_(code));
} }
void template17() void template17()
@ -1878,7 +1890,7 @@ private:
"\n" "\n"
"shared_ptr<int> i;\n"; "shared_ptr<int> i;\n";
// Assert that there are not segmentation fault.. // Assert that there is no segmentation fault..
sizeof_(code); sizeof_(code);
} }
@ -2063,8 +2075,7 @@ private:
" A<int> a2;\n" " A<int> a2;\n"
"}\n"; "}\n";
// The expected result.. const std::string wanted("template < class T , int n >"
const std::string expected("template < class T , int n >"
" class A" " class A"
" { T ar [ n ] ; } ;" " { T ar [ n ] ; } ;"
" void f ( )" " void f ( )"
@ -2076,7 +2087,17 @@ private:
" { int ar [ 2 ] ; }" " { int ar [ 2 ] ; }"
" class A<int,3>" " class A<int,3>"
" { int ar [ 3 ] ; }"); " { int ar [ 3 ] ; }");
TODO_ASSERT_EQUALS(expected, sizeof_(code));
const std::string current("; "
"void f ( ) "
"{ "
"A < int , ( int ) 2 > a1 ; "
"A<int,3> a2 ; "
"} "
"class A<int,3> "
"{ int ar [ 3 ] ; }"
);
TODO_ASSERT_EQUALS(wanted, current, sizeof_(code));
} }
} }
@ -2210,7 +2231,9 @@ private:
ASSERT_EQUALS("; a . x = b ( ) ; if ( ! ( a . x ) ) { ; }", simplifyIfAssign(";if(!(a->x=b()));")); ASSERT_EQUALS("; a . x = b ( ) ; if ( ! ( a . x ) ) { ; }", simplifyIfAssign(";if(!(a->x=b()));"));
ASSERT_EQUALS("A ( ) a = b ; if ( a ) { ; }", simplifyIfAssign("A() if(a=b);")); ASSERT_EQUALS("A ( ) a = b ; if ( a ) { ; }", simplifyIfAssign("A() if(a=b);"));
ASSERT_EQUALS("void foo ( int a ) { a = b ( ) ; if ( 0 <= a ) { ; } }", tok("void foo(int a) {if((a=b())>=0);}")); ASSERT_EQUALS("void foo ( int a ) { a = b ( ) ; if ( 0 <= a ) { ; } }", tok("void foo(int a) {if((a=b())>=0);}"));
TODO_ASSERT_EQUALS("void foo ( A a ) { a . c = b ( ) ; if ( 0 <= a . c ) { ; } }", tok("void foo(A a) {if((a.c=b())>=0);}")); TODO_ASSERT_EQUALS("void foo ( A a ) { a . c = b ( ) ; if ( 0 <= a . c ) { ; } }",
"void foo ( A a ) { a . c = b ( ) ; if ( a . c >= 0 ) { ; } }",
tok("void foo(A a) {if((a.c=b())>=0);}"));
} }
void ifAssignWithCast() void ifAssignWithCast()
@ -3541,14 +3564,20 @@ private:
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
// TODO: the definition and assignment should be split up // TODO: the definition and assignment should be split up
const char todo[] = const char wanted[] =
"; " "; "
"void g ( fp f ) " "void g ( fp f ) "
"{ " "{ "
"int ( * f2 ) ( ) ; f2 = ( int ( * ) ( ) ) f ; " "int ( * f2 ) ( ) ; f2 = ( int ( * ) ( ) ) f ; "
"}"; "}";
const char current[] =
"; "
"void g ( int ( * f ) ( ) ) "
"{ "
"int ( * f2 ) ( ) = ( int ( * ) ( ) ) f ; "
"}";
TODO_ASSERT_EQUALS(todo, tok(code, false)); TODO_ASSERT_EQUALS(wanted, current, tok(code, false));
} }
{ {
@ -6192,7 +6221,9 @@ private:
ASSERT_EQUALS("; struct A a ; a . buf = x ;", tok("; struct A a = { .buf = x };")); ASSERT_EQUALS("; struct A a ; a . buf = x ;", tok("; struct A a = { .buf = x };"));
ASSERT_EQUALS("; struct A a ; a . buf = & key ;", tok("; struct A a = { .buf = &key };")); ASSERT_EQUALS("; struct A a ; a . buf = & key ;", tok("; struct A a = { .buf = &key };"));
ASSERT_EQUALS("; struct ABC abc ; abc . a = 3 ; abc . b = x ; abc . c = & key ;", tok("; struct ABC abc = { .a = 3, .b = x, .c = &key };")); ASSERT_EQUALS("; struct ABC abc ; abc . a = 3 ; abc . b = x ; abc . c = & key ;", tok("; struct ABC abc = { .a = 3, .b = x, .c = &key };"));
TODO_ASSERT_EQUALS("; struct A a ; a . buf = { 0 } ;", tok("; struct A a = { .buf = {0} };")); TODO_ASSERT_EQUALS("; struct A a ; a . buf = { 0 } ;",
"; struct A a ; a = { . buf = { 0 } } ;",
tok("; struct A a = { .buf = {0} };"));
} }
void simplifyStructDecl() void simplifyStructDecl()

View File

@ -257,8 +257,7 @@ private:
" ++aI;\n" " ++aI;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:14] (error) After insert, the iterator 'aI' may be invalid", "", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:14] (error) After insert, the iterator 'aI' may be invalid", errout.str());
} }
void iterator8() void iterator8()
@ -629,8 +628,7 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", "", errout.str());
ASSERT_EQUALS("", errout.str());
} }
void eraseGoto() void eraseGoto()
@ -701,7 +699,7 @@ private:
" foo.erase(*it);\n" " foo.erase(*it);\n"
" }\n" " }\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\n", "", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"

View File

@ -176,9 +176,13 @@ void TestFixture::assertEqualsDouble(const char *filename, int linenr, double ex
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg); assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
} }
void TestFixture::todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual) void TestFixture::todoAssertEquals(const char *filename, int linenr,
const std::string &wanted,
const std::string &current,
const std::string &actual)
{ {
if (expected == actual) assertEquals(filename, linenr, current, actual);
if (wanted == actual)
{ {
assertEquals(filename, linenr, "TODO assertion", "The assertion succeeded"); assertEquals(filename, linenr, "TODO assertion", "The assertion succeeded");
} }
@ -188,13 +192,13 @@ void TestFixture::todoAssertEquals(const char *filename, int linenr, const std::
} }
} }
void TestFixture::todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual) void TestFixture::todoAssertEquals(const char *filename, int linenr, unsigned int wanted, unsigned int current, unsigned int actual)
{ {
std::ostringstream ostr1; std::ostringstream wantedStr, currentStr, actualStr;
ostr1 << expected; wantedStr << wanted;
std::ostringstream ostr2; currentStr << current;
ostr2 << actual; actualStr << actual;
todoAssertEquals(filename, linenr, ostr1.str(), ostr2.str()); todoAssertEquals(filename, linenr, wantedStr.str(), currentStr.str(), actualStr.str());
} }
void TestFixture::assertThrowFail(const char *filename, int linenr) void TestFixture::assertThrowFail(const char *filename, int linenr)

View File

@ -52,8 +52,10 @@ protected:
void assertEquals(const char *filename, int linenr, long long expected, long long actual, const std::string &msg=""); void assertEquals(const char *filename, int linenr, long long expected, long long actual, const std::string &msg="");
void assertEqualsDouble(const char *filename, int linenr, double expected, double actual, const std::string &msg=""); void assertEqualsDouble(const char *filename, int linenr, double expected, double actual, const std::string &msg="");
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual); void todoAssertEquals(const char *filename, int linenr, const std::string &wanted,
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual); const std::string &current, const std::string &actual);
void todoAssertEquals(const char *filename, int linenr, unsigned int wanted,
unsigned int current, unsigned int actual);
void assertThrowFail(const char *filename, int linenr); void assertThrowFail(const char *filename, int linenr);
void processOptions(const options& args); void processOptions(const options& args);
public: public:
@ -75,7 +77,7 @@ public:
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL) #define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG) #define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); } #define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
#define TODO_ASSERT_EQUALS( EXPECTED , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define TODO_ASSERT_EQUALS( WANTED , CURRENT , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; } #define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
#endif #endif

View File

@ -298,6 +298,9 @@ private:
TEST_CASE(java); TEST_CASE(java);
TEST_CASE(simplifyOperatorName); TEST_CASE(simplifyOperatorName);
// Some simple cleanups of unhandled macros in the global scope
TEST_CASE(removeMacrosInGlobalScope);
} }
@ -1129,11 +1132,9 @@ private:
TODO_ASSERT_EQUALS( TODO_ASSERT_EQUALS(
expected1 + " if ( true ) { a ( ) ; } }", expected1 + " if ( true ) { a ( ) ; } }",
simplifyKnownVariables(code));
ASSERT_EQUALS(
expected1 + " if ( b ) { a ( ) ; } }", expected1 + " if ( b ) { a ( ) ; } }",
simplifyKnownVariables(code)); simplifyKnownVariables(code));
} }
{ {
@ -1153,6 +1154,7 @@ private:
TODO_ASSERT_EQUALS( TODO_ASSERT_EQUALS(
"void f ( ) { bool b ; b = false ; { b = false ; } { b = true ; } if ( true ) { a ( ) ; } }", "void f ( ) { bool b ; b = false ; { b = false ; } { b = true ; } if ( true ) { a ( ) ; } }",
"void f ( ) { bool b ; b = false ; { b = false ; } { b = true ; } if ( b ) { a ( ) ; } }",
simplifyKnownVariables(code)); simplifyKnownVariables(code));
} }
@ -1363,7 +1365,6 @@ private:
" }\n" " }\n"
"}\n"; "}\n";
// wanted result
TODO_ASSERT_EQUALS( TODO_ASSERT_EQUALS(
"void foo ( int x ) " "void foo ( int x ) "
"{" "{"
@ -1371,16 +1372,14 @@ private:
" if ( x ) { a [ 0 ] = 0 ; c = 1 ; }" " if ( x ) { a [ 0 ] = 0 ; c = 1 ; }"
" else { a [ 0 ] = 0 ; } " " else { a [ 0 ] = 0 ; } "
"}", "}",
simplifyKnownVariables(code));
// Current result
ASSERT_EQUALS(
"void foo ( int x ) " "void foo ( int x ) "
"{" "{"
" int a [ 10 ] ; int c ; c = 0 ;" " int a [ 10 ] ; int c ; c = 0 ;"
" if ( x ) { a [ 0 ] = 0 ; c ++ ; }" " if ( x ) { a [ 0 ] = 0 ; c ++ ; }"
" else { a [ c ] = 0 ; } " " else { a [ c ] = 0 ; } "
"}", "}",
simplifyKnownVariables(code)); simplifyKnownVariables(code));
} }
@ -1635,14 +1634,21 @@ private:
" int i = v;\n" " int i = v;\n"
" return h | i;\n" " return h | i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n" "1: int foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4:\n" "4:\n"
"5: return u@1 | v@2 ;\n" "5: return u@1 | v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n"
"2: {\n"
"3: ;\n"
"4: int i@4 ; i@4 = v@2 ;\n"
"5: return u@1 | i@4 ;\n"
"6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1652,14 +1658,21 @@ private:
" int i = v;\n" " int i = v;\n"
" return h ^ i;\n" " return h ^ i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n" "1: int foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4:\n" "4:\n"
"5: return u@1 ^ v@2 ;\n" "5: return u@1 ^ v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n"
"2: {\n"
"3: ;\n"
"4: int i@4 ; i@4 = v@2 ;\n"
"5: return u@1 ^ i@4 ;\n"
"6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1669,14 +1682,21 @@ private:
" int i = v;\n" " int i = v;\n"
" return h % i;\n" " return h % i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n" "1: int foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4:\n" "4:\n"
"5: return u@1 % v@2 ;\n" "5: return u@1 % v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n"
"1: int foo ( int u@1 , int v@2 )\n"
"2: {\n"
"3: ;\n"
"4: int i@4 ; i@4 = v@2 ;\n"
"5: return u@1 % i@4 ;\n"
"6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1720,14 +1740,22 @@ private:
" int i = v;\n" " int i = v;\n"
" return h == i;\n" " return h == i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 == v@2 ;\n" "5: return u@1 == v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n"
"3: ;\n"
"4: int i@4 ; i@4 = v@2 ;\n"
"5: return u@1 == i@4 ;\n"
"6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1737,14 +1765,21 @@ private:
" int i = v;\n" " int i = v;\n"
" return h != i;\n" " return h != i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 != v@2 ;\n" "5: return u@1 != v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n"
"3: ;\n"
"4: int i@4 ; i@4 = v@2 ;\n"
"5: return u@1 != i@4 ;\n"
"6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1754,14 +1789,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h > i;\n" " return h > i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 > v@2 ;\n" "5: return u@1 > v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 > i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1771,14 +1807,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h >= i;\n" " return h >= i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 >= v@2 ;\n" "5: return u@1 >= v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 >= i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1788,14 +1825,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h < i;\n" " return h < i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 < v@2 ;\n" "5: return u@1 < v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 < i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1805,14 +1843,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h <= i;\n" " return h <= i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 <= v@2 ;\n" "5: return u@1 <= v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 <= i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1822,14 +1861,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h && i;\n" " return h && i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 && v@2 ;\n" "5: return u@1 && v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 && i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
{ {
@ -1839,14 +1879,15 @@ private:
" int i = v;\n" " int i = v;\n"
" return h || i;\n" " return h || i;\n"
"}\n"; "}\n";
const char expected[] = "\n\n##file 0\n" const char wanted[] = "\n\n##file 0\n"
"1: bool foo ( int u@1 , int v@2 )\n" "1: bool foo ( int u@1 , int v@2 )\n"
"2: {\n" "2: {\n"
"3: ;\n" "3: ;\n"
"4: ;\n" "4: ;\n"
"5: return u@1 || v@2 ;\n" "5: return u@1 || v@2 ;\n"
"6: }\n"; "6: }\n";
TODO_ASSERT_EQUALS(expected, tokenizeDebugListing(code, true)); const char current[] = "\n\n##file 0\n1: bool foo ( int u@1 , int v@2 )\n2: {\n3: ;\n4: int i@4 ; i@4 = v@2 ;\n5: return u@1 || i@4 ;\n6: }\n";
TODO_ASSERT_EQUALS(wanted, current, tokenizeDebugListing(code, true));
} }
} }
@ -3209,7 +3250,7 @@ private:
" A::buf[10] = 0;\n" " A::buf[10] = 0;\n"
"}"); "}");
const std::string expected("\n\n##file 0\n" const std::string wanted("\n\n##file 0\n"
"1: class A\n" "1: class A\n"
"2: {\n" "2: {\n"
"3: public:\n" "3: public:\n"
@ -3222,7 +3263,8 @@ private:
"10: A :: buf@1 [ 10 ] = 0 ;\n" "10: A :: buf@1 [ 10 ] = 0 ;\n"
"11: }\n"); "11: }\n");
TODO_ASSERT_EQUALS(expected, actual); const char current[] = "\n\n##file 0\n1: class A\n2: {\n3: public:\n4: static char buf@1 [ 20 ] ;\n5: } ;\n6: char A :: buf [ 20 ] ;\n7: int main ( )\n8: {\n9: char buf@2 [ 2 ] ;\n10: A :: buf [ 10 ] = 0 ;\n11: }\n";
TODO_ASSERT_EQUALS(wanted, current, actual);
} }
void varidclass7() void varidclass7()
@ -3892,12 +3934,12 @@ private:
void vardecl_stl_2() void vardecl_stl_2()
{ {
const char code1[] = "{ std::string x = \"abc\"; }"; const char code1[] = "{ std::string x = \"abc\"; }";
TODO_ASSERT_EQUALS("{ std :: string x ; x = \"abc\" ; }", tokenizeAndStringify(code1)); TODO_ASSERT_EQUALS("{ std :: string x ; x = \"abc\" ; }",
ASSERT_EQUALS("{ std :: string x = \"abc\" ; }", tokenizeAndStringify(code1)); "{ std :: string x = \"abc\" ; }", tokenizeAndStringify(code1));
const char code2[] = "{ std::vector<int> x = y; }"; const char code2[] = "{ std::vector<int> x = y; }";
TODO_ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }", tokenizeAndStringify(code2)); TODO_ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }",
ASSERT_EQUALS("{ std :: vector < int > x = y ; }", tokenizeAndStringify(code2)); "{ std :: vector < int > x = y ; }", tokenizeAndStringify(code2));
} }
void vardecl_template() void vardecl_template()
@ -4566,8 +4608,8 @@ private:
{ {
// tokenize ">>" into "> >" // tokenize ">>" into "> >"
const char *code = "list<list<int>> ints;\n"; const char *code = "list<list<int>> ints;\n";
ASSERT_EQUALS("list < list < int >> ints ;", tokenizeAndStringify(code)); TODO_ASSERT_EQUALS("list < list < int > > ints ;",
TODO_ASSERT_EQUALS("list < list < int > > ints ;", tokenizeAndStringify(code)); "list < list < int >> ints ;", tokenizeAndStringify(code));
} }
void cpp0xdefault() void cpp0xdefault()
@ -4599,8 +4641,8 @@ private:
" foo();" " foo();"
"}" "}"
"foo::foo() = delete;"; "foo::foo() = delete;";
ASSERT_EQUALS("struct foo { foo ( ) ; } foo :: foo ( ) = delete ;", tokenizeAndStringify(code)); TODO_ASSERT_EQUALS("struct foo { }",
TODO_ASSERT_EQUALS("struct foo { }", tokenizeAndStringify(code)); "struct foo { foo ( ) ; } foo :: foo ( ) = delete ;", tokenizeAndStringify(code));
} }
} }
@ -5247,6 +5289,12 @@ private:
ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false)); ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false));
} }
void removeMacrosInGlobalScope()
{
// remove some unhandled macros in the global scope.
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }"));
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)

View File

@ -798,8 +798,8 @@ private:
" x--;\n" " x--;\n"
" }\n" " }\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: pItem\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: pItem\n",
ASSERT_EQUALS("", errout.str()); // current result "", errout.str());
} }
// switch.. // switch..
@ -1364,8 +1364,8 @@ private:
" int x[10];\n" " int x[10];\n"
" calc(x,10);\n" " calc(x,10);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n",
ASSERT_EQUALS("", errout.str()); "", errout.str());
// #2401 - unknown function/macro might init the variable // #2401 - unknown function/macro might init the variable
checkUninitVar("int f() {\n" checkUninitVar("int f() {\n"

View File

@ -657,7 +657,8 @@ private:
" int a[10];\n" " int a[10];\n"
" f(a[0]);\n" " f(a[0]);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is not assigned a value\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is not assigned a value\n",
"", errout.str());
// f() can not write a (not supported yet) // f() can not write a (not supported yet)
functionVariableUsage("void f(const int & i) { }\n" functionVariableUsage("void f(const int & i) { }\n"
@ -666,7 +667,8 @@ private:
" int a[10];\n" " int a[10];\n"
" f(a[0]);\n" " f(a[0]);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is not assigned a value\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'a' is not assigned a value\n",
"", errout.str());
// f() writes a // f() writes a
functionVariableUsage("void f(int & i) { }\n" functionVariableUsage("void f(int & i) { }\n"
@ -811,37 +813,37 @@ private:
"{\n" "{\n"
" int * i[2];\n" " int * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"
" const int * i[2];\n" " const int * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"
" void * i[2];\n" " void * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"
" const void * i[2];\n" " const void * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"
" struct A * i[2];\n" " struct A * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"
" const struct A * i[2];\n" " const struct A * i[2];\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: i\n", "", errout.str());
functionVariableUsage("void foo(int n)\n" functionVariableUsage("void foo(int n)\n"
"{\n" "{\n"
@ -1076,15 +1078,14 @@ private:
" a = b = c;\n" " a = b = c;\n"
"\n" "\n"
"}\n"); "}\n");
ASSERT_EQUALS(
"[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n"
"[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used\n",
errout.str());
TODO_ASSERT_EQUALS( TODO_ASSERT_EQUALS(
"[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n" "[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n"
"[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used\n" "[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used\n"
"[test.cpp:3]: (style) Variable 'c' is assigned a value that is never used\n", "[test.cpp:3]: (style) Variable 'c' is assigned a value that is never used\n",
"[test.cpp:3]: (style) Variable 'a' is assigned a value that is never used\n"
"[test.cpp:3]: (style) Variable 'b' is assigned a value that is never used\n",
errout.str()); errout.str());
} }
@ -2311,9 +2312,10 @@ private:
" func();\n" " func();\n"
" } while(a--);\n" " } while(a--);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: x\n" TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: x\n"
"[test.cpp:4]: (style) Unused variable: z\n", errout.str()); "[test.cpp:4]: (style) Unused variable: z\n",
"", errout.str());
} }
void localvarStruct4() void localvarStruct4()