really fix #3527 (Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers)

This commit is contained in:
Robert Reif 2012-01-28 20:58:51 -05:00
parent 91a01a0a0d
commit a37031944e
4 changed files with 55 additions and 2 deletions

View File

@ -2556,8 +2556,6 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke
return;
const unsigned int varid = classtok->varId();
if (varid == 0)
return;
// Parse public functions..
// If they allocate member variables, they should also deallocate

View File

@ -2108,6 +2108,9 @@ bool Tokenizer::tokenize(std::istream &code,
// remove Borland stuff..
simplifyBorland();
// remove wxWidgets stuff..
simplifyWxWidgets();
// Remove "volatile", "inline", "register", and "restrict"
simplifyKeyword();
@ -8994,6 +8997,32 @@ void Tokenizer::simplifyQtSignalsSlots()
}
}
void Tokenizer::simplifyWxWidgets()
{
std::set<std::string> macros;
macros.insert("WXDLLIMPEXP_FWD_BASE");
macros.insert("WXDLLIMPEXP_FWD_NET");
macros.insert("WXDLLIMPEXP_FWD_CORE");
macros.insert("WXDLLIMPEXP_FWD_ADV");
macros.insert("WXDLLIMPEXP_FWD_QA");
macros.insert("WXDLLIMPEXP_FWD_HTML");
macros.insert("WXDLLIMPEXP_FWD_GL");
macros.insert("WXDLLIMPEXP_FWD_XML");
macros.insert("WXDLLIMPEXP_FWD_XRC");
macros.insert("WXDLLIMPEXP_FWD_AUI");
macros.insert("WXDLLIMPEXP_FWD_PROPGRID");
macros.insert("WXDLLIMPEXP_FWD_RICHTEXT");
macros.insert("WXDLLIMPEXP_FWD_MEDIA");
macros.insert("WXDLLIMPEXP_FWD_STC");
macros.insert("WXDLLIMPEXP_FWD_WEBVIEW");
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (tok->next() && macros.find(tok->next()->str()) != macros.end())
tok->deleteNext();
}
}
const SymbolDatabase *Tokenizer::getSymbolDatabase() const
{
if (!_symbolDatabase)

View File

@ -671,6 +671,11 @@ public:
*/
void simplifyQtSignalsSlots();
/**
* Remove wxWidgets macros
*/
void simplifyWxWidgets();
/**
* Collapse operator name tokens into single token
* operator = => operator=

View File

@ -355,6 +355,8 @@ private:
TEST_CASE(Qt);
TEST_CASE(wxWidgets); // ticket #3527
TEST_CASE(sql);
TEST_CASE(simplifyLogicalOperators);
@ -5903,6 +5905,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
// ticket #3527
void wxWidgets() {
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_BASE wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_NET wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_CORE wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_ADV wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_QA wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_HTML wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_GL wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_XML wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_XRC wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_AUI wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_PROPGRID wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_RICHTEXT wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_MEDIA wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_STC wxCheckBox;"));
ASSERT_EQUALS("class wxCheckBox ;", tokenizeAndStringify("class WXDLLIMPEXP_FWD_WEBVIEW wxCheckBox;"));
}
void sql() {
// Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages
// ticket: #1959