Fixed #4686 (Prefer prefix ++/-- operators for non-primitive types with template iterator)
This commit is contained in:
parent
274aa87331
commit
a3f9b5c07d
|
@ -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%")) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in New Issue