Fixed #1449 (segmentation fault of cppcheck)
This commit is contained in:
parent
d9df3d5c6e
commit
7d8adfb4df
|
@ -455,7 +455,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// look backwards
|
// look backwards
|
||||||
if (Token::Match(tok->previous(), "typedef|}") ||
|
if (Token::Match(tok->previous(), "typedef|}|>") ||
|
||||||
(Token::Match(tok->previous(), "%type%") &&
|
(Token::Match(tok->previous(), "%type%") &&
|
||||||
!Token::Match(tok->previous(), "return|new|const")))
|
!Token::Match(tok->previous(), "return|new|const")))
|
||||||
{
|
{
|
||||||
|
@ -812,8 +812,14 @@ void Tokenizer::simplifyTypedef()
|
||||||
// skip to end of scope if not already there
|
// skip to end of scope if not already there
|
||||||
if (tok2->str() != "}")
|
if (tok2->str() != "}")
|
||||||
{
|
{
|
||||||
while (tok2 && tok2->next()->str() != "}")
|
int level = 0;
|
||||||
|
while (tok2 && tok2->next() && (tok2->next()->str() != "}" || level))
|
||||||
{
|
{
|
||||||
|
if (tok2->next()->str() == "{")
|
||||||
|
level++;
|
||||||
|
else if (tok2->next()->str() == "}")
|
||||||
|
level--;
|
||||||
|
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef34); // ticket #1411
|
TEST_CASE(simplifyTypedef34); // ticket #1411
|
||||||
TEST_CASE(simplifyTypedef35);
|
TEST_CASE(simplifyTypedef35);
|
||||||
TEST_CASE(simplifyTypedef36); // ticket #1434
|
TEST_CASE(simplifyTypedef36); // ticket #1434
|
||||||
|
TEST_CASE(simplifyTypedef37); // ticket #1449
|
||||||
TEST_CASE(reverseArraySyntax)
|
TEST_CASE(reverseArraySyntax)
|
||||||
TEST_CASE(simplify_numeric_condition)
|
TEST_CASE(simplify_numeric_condition)
|
||||||
|
|
||||||
|
@ -3298,6 +3299,36 @@ private:
|
||||||
ASSERT_EQUALS(expected, tok(code, false));
|
ASSERT_EQUALS(expected, tok(code, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef37()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// ticket #1449
|
||||||
|
const char code[] = "template <class T> class V {};\n"
|
||||||
|
"typedef V<int> A;\n"
|
||||||
|
"typedef int B;\n"
|
||||||
|
"typedef V<int> A;\n"
|
||||||
|
"typedef int B;";
|
||||||
|
|
||||||
|
checkSimplifyTypedef(code);
|
||||||
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Typedef 'A' hides typedef with same name\n"
|
||||||
|
"[test.cpp:5] -> [test.cpp:3]: (style) Typedef 'B' hides typedef with same name\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char code[] = "typedef int INT;\n"
|
||||||
|
"void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" INT i; { }\n"
|
||||||
|
"}";
|
||||||
|
const char expected[] = "; "
|
||||||
|
"void f ( ) "
|
||||||
|
"{ "
|
||||||
|
"int i ; { } "
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(expected, tok(code, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void reverseArraySyntax()
|
void reverseArraySyntax()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
|
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
|
||||||
|
|
Loading…
Reference in New Issue