fix #1987 (Internal error:: CheckClass::SpaceInfo::getVarList found variable 'element_size' with varid 0.)

This commit is contained in:
Robert Reif 2011-03-19 16:00:43 -04:00
parent 2dcd0128b0
commit 92316e5745
2 changed files with 24 additions and 4 deletions

View File

@ -9315,15 +9315,22 @@ void Tokenizer::simplifyBitfields()
{
Token *last = 0;
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% : %any% ;|,") &&
tok->next()->str() != "case")
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") &&
!Token::Match(tok->next(), "case|public|protected|private"))
{
int offset = 0;
if (tok->next()->str() == "const")
offset = 1;
last = tok->tokAt(5 + offset);
Token::eraseTokens(tok->tokAt(2 + offset), tok->tokAt(5 + offset));
Token *tok1 = tok->tokAt(2 + offset);
if (tok1->tokAt(2)->isBoolean() || Token::Match(tok1->tokAt(2), "%num%") ||
!Token::Match(tok1->tokAt(2), "public|protected|private| %type% ::|<|,|{|;"))
{
while (tok1->next() && !Token::Match(tok1->next(), ";|,"))
tok1->deleteNext();
last = tok1->next();
}
}
else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
tok->next()->str() != "default")

View File

@ -289,6 +289,7 @@ private:
TEST_CASE(bitfields4); // ticket #1956
TEST_CASE(bitfields5); // ticket #1956
TEST_CASE(bitfields6); // ticket #2595
TEST_CASE(bitfields7); // ticket #1987
TEST_CASE(microsoftMFC);
@ -5273,6 +5274,18 @@ private:
ASSERT_EQUALS("void f ( int a ) { switch ( a ) { default : ; break ; } }", tokenizeAndStringify(code5,true));
}
void bitfields7() // ticket #1987
{
const char code[] = "typedef struct Descriptor {"
" unsigned element_size: 8* sizeof( unsigned );"
"} Descriptor;";
const char expected[] = "struct Descriptor { "
"unsigned int element_size ; "
"} ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code,false));
ASSERT_EQUALS("", errout.str());
}
void microsoftMFC()
{
const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };";