Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4742,9 +4742,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Is there C++ code in C file?
validateC();

// remove MACRO in variable declaration: MACRO int x;
removeMacroInVarDecl();

// Combine strings and character literals, e.g. L"string", L'c', "string1" "string2"
combineStringAndCharLiterals();

Expand Down Expand Up @@ -5649,35 +5646,6 @@ void Tokenizer::removeMacroInClassDef()

//---------------------------------------------------------------------------

void Tokenizer::removeMacroInVarDecl()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %name% (") && tok->next()->isUpperCaseName()) {
// goto ')' parentheses
const Token *tok2 = tok;
int parlevel = 0;
while (tok2) {
if (tok2->str() == "(")
++parlevel;
else if (tok2->str() == ")") {
if (--parlevel <= 0)
break;
}
tok2 = tok2->next();
}
tok2 = tok2 ? tok2->next() : nullptr;

// check if this is a variable declaration..
const Token *tok3 = tok2;
while (tok3 && tok3->isUpperCaseName())
tok3 = tok3->next();
if (tok3 && (tok3->isStandardType() || Token::Match(tok3,"const|static|struct|union|class")))
Token::eraseTokens(tok,tok2);
}
}
}
//---------------------------------------------------------------------------

void Tokenizer::addSemicolonAfterUnknownMacro()
{
if (!isCPP())
Expand Down
3 changes: 0 additions & 3 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ class CPPCHECKLIB Tokenizer {
*/
void removeMacroInClassDef();

/** Remove unknown macro in variable declarations: PROGMEM char x; */
void removeMacroInVarDecl();

/** Add parentheses for sizeof: sizeof x => sizeof(x) */
void sizeofAddParentheses();

Expand Down
14 changes: 0 additions & 14 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ class TestTokenizer : public TestFixture {

// Some simple cleanups of unhandled macros in the global scope
TEST_CASE(removeMacrosInGlobalScope);
TEST_CASE(removeMacroInVarDecl);

TEST_CASE(addSemicolonAfterUnknownMacro);

Expand Down Expand Up @@ -5318,19 +5317,6 @@ class TestTokenizer : public TestFixture {
InternalError);
}

void removeMacroInVarDecl() { // #4304
// only remove macros with parentheses (those hurt most)
ASSERT_EQUALS("void f ( ) { PROGMEM int x ; }", tokenizeAndStringify("void f() { PROGMEM int x ; }"));
ASSERT_EQUALS("void f ( ) { int x ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") int x ; }"));

// various variable declarations
ASSERT_EQUALS("void f ( ) { CONST int x ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST int x ; }"));
ASSERT_EQUALS("void f ( ) { char a [ 4 ] ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") char a[4]; }"));
ASSERT_EQUALS("void f ( ) { const char a [ 4 ] ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") const char a[4]; }"));
ASSERT_EQUALS("void f ( ) { struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") struct ABC abc; }"));
ASSERT_EQUALS("void f ( ) { CONST struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST struct ABC abc; }"));
}

void addSemicolonAfterUnknownMacro() {
// #6975
ASSERT_EQUALS("void f ( ) { MACRO ( ) ; try { } }", tokenizeAndStringify("void f() { MACRO() try {} }"));
Expand Down
8 changes: 8 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,14 @@ class TestUnusedVar : public TestFixture {
" delete [] piArray;\n"
"}");
ASSERT_EQUALS("", errout.str());

functionVariableUsage("int f() {\n" // #9877
" const std::vector<int> x = get();\n"
" MACRO(2U, x.size())\n"
" int i = 0;\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void localvar44() { // #4020 - FP
Expand Down