Fixed #4686 (Prefer prefix ++/-- operators for non-primitive types with template iterator)

This commit is contained in:
Robert Reif 2013-03-30 13:49:56 +01:00 committed by Daniel Marjamäki
parent 274aa87331
commit a3f9b5c07d
3 changed files with 16 additions and 3 deletions

View File

@ -2302,9 +2302,12 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const
if (found) {
localVarTok = skipPointers(closeTok->next());
if (Token::Match(localVarTok, ":: %type% %var% ;|=")) {
localTypeTok = localVarTok->next();
localVarTok = localVarTok->tokAt(2);
if (Token::Match(localVarTok, ":: %type% %var% ;|=|(")) {
if (localVarTok->strAt(3) != "(" ||
Token::simpleMatch(localVarTok->linkAt(3), ") ;")) {
localTypeTok = localVarTok->next();
localVarTok = localVarTok->tokAt(2);
}
}
}
} else if (Token::Match(localTypeTok, "%type%")) {

View File

@ -62,6 +62,7 @@ private:
TEST_CASE(test2168);
TEST_CASE(pointer); // #2321 - postincrement of pointer is OK
TEST_CASE(testHangWithInvalidCode); // #2847 - cppcheck hangs with 100% cpu load
TEST_CASE(testtemplate); // #4686
}
void testHangWithInvalidCode() {
@ -345,6 +346,14 @@ private:
"p++;\n");
ASSERT_EQUALS("", errout.str());
}
void testtemplate() {
check("bool foo() {\n"
" std::vector<FilterConfigCacheEntry>::iterator aIter(aImport.begin());\n"
" aIter++;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
}
};
REGISTER_TEST(TestPostfixOperator)

View File

@ -322,6 +322,7 @@ private:
void readCode4() {
const char code[] = "char c = '\\ ';";
Settings settings;
errout.str("");
Preprocessor preprocessor(&settings, this);
std::istringstream istr(code);
ASSERT_EQUALS("char c = '\\ ';", preprocessor.read(istr,"test.c"));