Fixed #1197 (Segmentation fault when we define function which was already defined by preprocessor)
http://sourceforge.net/apps/trac/cppcheck/ticket/1197
This commit is contained in:
parent
ddfd0b948e
commit
b816968f28
|
@ -5147,17 +5147,6 @@ void Tokenizer::simplifyWhile0()
|
||||||
if (!Token::simpleMatch(tok, "while ( 0 )"))
|
if (!Token::simpleMatch(tok, "while ( 0 )"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// remove "while (0) { .. }"
|
|
||||||
if (Token::simpleMatch(tok->tokAt(4), "{"))
|
|
||||||
{
|
|
||||||
const Token *end = tok->tokAt(4)->link();
|
|
||||||
if (!findmatch(tok, end, "continue|break"))
|
|
||||||
{
|
|
||||||
Token::eraseTokens(tok, end ? end->next() : 0);
|
|
||||||
tok->deleteThis(); // delete "while"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->previous(), "}"))
|
if (Token::simpleMatch(tok->previous(), "}"))
|
||||||
{
|
{
|
||||||
// find "do"
|
// find "do"
|
||||||
|
@ -5180,5 +5169,17 @@ void Tokenizer::simplifyWhile0()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove "while (0) { .. }"
|
||||||
|
if (Token::simpleMatch(tok->tokAt(4), "{"))
|
||||||
|
{
|
||||||
|
const Token *end = tok->tokAt(4)->link();
|
||||||
|
if (!findmatch(tok, end, "continue|break"))
|
||||||
|
{
|
||||||
|
Token::eraseTokens(tok, end ? end->next() : 0);
|
||||||
|
tok->deleteThis(); // delete "while"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,7 @@ private:
|
||||||
|
|
||||||
// simplify "while (0)"
|
// simplify "while (0)"
|
||||||
TEST_CASE(while0);
|
TEST_CASE(while0);
|
||||||
|
TEST_CASE(while1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool simplify = true)
|
std::string tok(const char code[], bool simplify = true)
|
||||||
|
@ -2551,6 +2552,15 @@ private:
|
||||||
ASSERT_EQUALS("; do { continue ; } while ( false ) ;", tok("; do { continue ; } while (0);"));
|
ASSERT_EQUALS("; do { continue ; } while ( false ) ;", tok("; do { continue ; } while (0);"));
|
||||||
ASSERT_EQUALS("; do { break ; } while ( false ) ;", tok("; do { break; } while (0);"));
|
ASSERT_EQUALS("; do { break ; } while ( false ) ;", tok("; do { break; } while (0);"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void while1()
|
||||||
|
{
|
||||||
|
// ticket #1197
|
||||||
|
const char code[] = "void do {} while (0) { }";
|
||||||
|
const char expected[] = "void { }";
|
||||||
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestSimplifyTokens)
|
REGISTER_TEST(TestSimplifyTokens)
|
||||||
|
|
Loading…
Reference in New Issue