Fixed #3314 (cppcheck incorrectly reporting Syntax error.)

This commit is contained in:
Daniel Marjamäki 2011-11-11 10:53:49 +01:00
parent 8bbd535267
commit 34e40502c6
2 changed files with 16 additions and 0 deletions

View File

@ -1097,6 +1097,14 @@ void Tokenizer::simplifyTypedef()
continue; continue;
} }
// unhandled function pointer, skip it and continue
else if (Token::Match(tok->tokAt(offset), "( %type% ::") &&
Token::Match(tok->tokAt(offset)->link()->tokAt(-3), ":: * %var% ) (")) {
unsupportedTypedef(typeDef);
tok = deleteInvalidTypedef(typeDef);
continue;
}
// function pointer // function pointer
else if (Token::Match(tok->tokAt(offset), "( * %var% ) (")) { else if (Token::Match(tok->tokAt(offset), "( * %var% ) (")) {
// name token wasn't a name, it was part of the type // name token wasn't a name, it was part of the type

View File

@ -610,6 +610,14 @@ private:
tokenizeAndStringify(code.c_str(), true); tokenizeAndStringify(code.c_str(), true);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
} }
{
// #3314 - don't report syntax error.
errout.str("");
const std::string code("struct A { typedef B::C (A::*f)(); };");
tokenizeAndStringify(code.c_str(), true);
ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef B :: C ( A :: * f ) ( ) ;'. The checking continues anyway.\n", errout.str());
}
} }
void wrong_syntax_if_macro() { void wrong_syntax_if_macro() {