Fixed #3855 (false positive: (error) Instance of 'locale' object destroyed immediately)

This commit is contained in:
Daniel Marjamäki 2012-06-13 19:21:20 +02:00
parent cc5e06b5d2
commit 4b6e1c6946
2 changed files with 30 additions and 15 deletions

View File

@ -3454,32 +3454,41 @@ void Tokenizer::removeMacrosInGlobalScope()
tok->deleteNext();
}
if (Token::Match(tok, "[;{}] %type% (") && CheckNullPointer::isUpper(tok->next()->str())) {
unsigned int par = 0;
const Token *tok2;
for (tok2 = tok; tok2; tok2 = tok2->next()) {
if (tok2->str() == "(")
++par;
else if (tok2->str() == ")") {
if (par <= 1)
break;
--par;
if (Token::Match(tok, "[;{}] %type%") && CheckNullPointer::isUpper(tok->next()->str())) {
const Token *tok2 = tok->tokAt(2);
if (tok2 && tok2->str() == "(") {
unsigned int par = 0;
for (; tok2; tok2 = tok2->next()) {
if (tok2->str() == "(")
++par;
else if (tok2->str() == ")") {
if (par <= 1)
break;
--par;
}
}
if (tok2 && tok2->str() == ")")
tok2 = tok2->next();
}
// remove unknown macros before namespace|class|struct|union
if (Token::Match(tok2, ") namespace|class|struct|union")) {
Token::eraseTokens(tok, tok2->next());
if (Token::Match(tok2, "namespace|class|struct|union")) {
// is there a "{" for?
const Token *tok3 = tok2;
while (tok3 && !Token::Match(tok3,"[;{}()]"))
tok3 = tok3->next();
if (tok3 && tok3->str() == "{")
Token::eraseTokens(tok, tok2);
continue;
}
// remove unknown macros before foo::foo(
if (Token::Match(tok2, ") %type% :: %type%")) {
const Token *tok3 = tok2->next();
if (Token::Match(tok2, "%type% :: %type%")) {
const Token *tok3 = tok2;
while (Token::Match(tok3, "%type% :: %type% ::"))
tok3 = tok3->tokAt(2);
if (Token::Match(tok3, "%type% :: %type% (") && tok3->str() == tok3->strAt(2))
Token::eraseTokens(tok, tok2->next());
Token::eraseTokens(tok, tok2);
continue;
}
}

View File

@ -6525,6 +6525,12 @@ private:
// #3750
ASSERT_EQUALS("; foo :: foo ( ) { }",
tokenizeAndStringify("; AB(foo*) foo::foo() { }"));
// #3855
ASSERT_EQUALS("; class foo { }",
tokenizeAndStringify("; AB class foo { }"));
ASSERT_EQUALS("; CONST struct ABC abc ;",
tokenizeAndStringify("; CONST struct ABC abc ;"));
}
void multipleAssignment() {