Fix ticket #435 (False positive: Invalid number of character when ({}) is used in code)

http://sourceforge.net/apps/trac/cppcheck/ticket/435
This commit is contained in:
Reijo Tomperi 2009-06-22 23:54:11 +03:00
parent e3271115f2
commit bdf1987cc4
2 changed files with 18 additions and 1 deletions

View File

@ -1727,7 +1727,7 @@ bool Tokenizer::simplifyIfAddBraces()
else if (tempToken->str() == "}")
{
--indentlevel;
if (indentlevel == 0)
if (indentlevel == 0 && parlevel == 0)
break;
}

View File

@ -79,6 +79,7 @@ private:
TEST_CASE(ifAddBraces4);
TEST_CASE(ifAddBraces5);
TEST_CASE(ifAddBraces6);
TEST_CASE(ifAddBraces7);
TEST_CASE(whileAddBraces);
@ -444,6 +445,22 @@ private:
ASSERT_EQUALS("if ( )", tokenizeAndStringify(code, true));
}
void ifAddBraces7()
{
const char code[] = "void f()\n"
"{\n"
"int a;\n"
"if( a )\n"
" ({a=4;}),({a=5;});\n"
"}\n";
ASSERT_EQUALS("void f ( )\n"
"{\n"
"int a ;\n"
"if ( a ) {\n"
"( { a = 4 ; } ) , ( { a = 5 ; } ) ; }\n"
"}", tokenizeAndStringify(code, true));
}
void whileAddBraces()
{
{