From 92316e5745790f7d7619d1bd864c2a1d833ee251 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 19 Mar 2011 16:00:43 -0400 Subject: [PATCH] fix #1987 (Internal error:: CheckClass::SpaceInfo::getVarList found variable 'element_size' with varid 0.) --- lib/tokenize.cpp | 15 +++++++++++---- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a73e8e7a9..65fa04dd0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f1ce4876e..b94295294 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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; };";