Fixed #3750 (false positive: C-style pointer casting)

This commit is contained in:
Daniel Marjamäki 2012-06-12 18:45:31 +02:00
parent 08a3d0737e
commit 54a66391d8
2 changed files with 35 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "symboldatabase.h"
#include "templatesimplifier.h"
#include "timer.h"
#include "checknullpointer.h" // isUpper
#include <cstring>
#include <sstream>
@ -3447,6 +3448,36 @@ 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;
}
}
// remove unknown macros before namespace|class|struct|union
if (Token::Match(tok2, ") namespace|class|struct|union")) {
Token::eraseTokens(tok, tok2->next());
continue;
}
// remove unknown macros before foo::foo(
if (Token::Match(tok2, ") %type% :: %type%")) {
const Token *tok3 = tok2->next();
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());
continue;
}
}
if (tok->str() == "{")
tok = tok->link();
}

View File

@ -6514,6 +6514,10 @@ private:
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }"));
ASSERT_EQUALS("struct Foo { } ;", tokenizeAndStringify("struct __declspec(dllexport) Foo {};"));
ASSERT_EQUALS("ABA ( ) namespace { }", tokenizeAndStringify("ABA() namespace { }"));
// #3750
ASSERT_EQUALS("; foo :: foo ( ) { }",
tokenizeAndStringify("; AB(foo*) foo::foo() { }"));
}
void multipleAssignment() {