Fixed #2426 (### Internal error in Cppcheck. Please report it.)
This commit is contained in:
parent
56ffde402f
commit
bfc95e01c1
|
@ -665,8 +665,16 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
|
||||||
|
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
const Token *tok1 = tok;
|
const Token *tok1 = tok;
|
||||||
while (tok && tok->str() != ";")
|
int level = 0;
|
||||||
|
while (tok)
|
||||||
{
|
{
|
||||||
|
if (level == 0 && tok->str() == ";")
|
||||||
|
break;
|
||||||
|
else if (tok->str() == "{")
|
||||||
|
level++;
|
||||||
|
else if (tok->str() == "}")
|
||||||
|
level--;
|
||||||
|
|
||||||
if (tok != tok1)
|
if (tok != tok1)
|
||||||
str << " ";
|
str << " ";
|
||||||
str << tok->str();
|
str << tok->str();
|
||||||
|
@ -694,10 +702,19 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const
|
||||||
Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
|
Token * Tokenizer::deleteInvalidTypedef(Token *typeDef)
|
||||||
{
|
{
|
||||||
Token *tok = NULL;
|
Token *tok = NULL;
|
||||||
|
int level = 0;
|
||||||
|
|
||||||
// remove typedef but leave ;
|
// remove typedef but leave ;
|
||||||
while (typeDef->next() && typeDef->next()->str() != ";")
|
while (typeDef->next())
|
||||||
|
{
|
||||||
|
if (level == 0 && typeDef->next()->str() == ";")
|
||||||
|
break;
|
||||||
|
else if (typeDef->next()->str() == "{")
|
||||||
|
level++;
|
||||||
|
else if (typeDef->next()->str() == "}")
|
||||||
|
level--;
|
||||||
typeDef->deleteNext();
|
typeDef->deleteNext();
|
||||||
|
}
|
||||||
|
|
||||||
if (typeDef != _tokens)
|
if (typeDef != _tokens)
|
||||||
{
|
{
|
||||||
|
|
|
@ -232,6 +232,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef72); // ticket #2375
|
TEST_CASE(simplifyTypedef72); // ticket #2375
|
||||||
TEST_CASE(simplifyTypedef73); // ticket #2412
|
TEST_CASE(simplifyTypedef73); // ticket #2412
|
||||||
TEST_CASE(simplifyTypedef74); // ticket #2414
|
TEST_CASE(simplifyTypedef74); // ticket #2414
|
||||||
|
TEST_CASE(simplifyTypedef75); // ticket #2426
|
||||||
|
|
||||||
TEST_CASE(simplifyTypedefFunction1);
|
TEST_CASE(simplifyTypedefFunction1);
|
||||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||||
|
@ -4786,6 +4787,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef75() // ticket #2426
|
||||||
|
{
|
||||||
|
const char code[] = "typedef _Packed struct S { long l; }; \n";
|
||||||
|
const std::string expected = ";";
|
||||||
|
ASSERT_EQUALS(expected, sizeof_(code));
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyTypedefFunction1()
|
void simplifyTypedefFunction1()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue