Skip to content

Commit 352c459

Browse files
committed
Merge pull request danmar#194 from simartin/ticket_5121
Ticket danmar#5121: Handle static variable declarations depending on one another
2 parents 14787cd + d67722e commit 352c459

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5288,9 +5288,9 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, Token * tokEnd, bool only_k_r_
52885288

52895289
if (tok2->str() == "=") {
52905290
if (isstatic) {
5291-
if (Token::Match(tok2->next(), "%num% ,"))
5291+
if (Token::Match(tok2->next(), "%num%|%var% ,")) // ticket #5121
52925292
tok2 = tok2->tokAt(2);
5293-
else if (Token::Match(tok2->next(), "( %num% ) ,")) { // ticket #4450
5293+
else if (Token::Match(tok2->next(), "( %num%|%var% ) ,")) { // ticket #4450
52945294
tok2->deleteNext();
52955295
tok2->next()->deleteNext();
52965296
tok2 = tok2->tokAt(2);

test/testtokenize.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,11 +5670,32 @@ class TestTokenizer : public TestFixture {
56705670
}
56715671

56725672
{
5673+
// Ticket #4450
56735674
const char code[] = "static int large_eeprom_type = (13 | (5)), "
56745675
"default_flash_type = 42;";
56755676
ASSERT_EQUALS("static int large_eeprom_type = 13 ; static int default_flash_type = 42 ;",
56765677
tokenizeAndStringify(code));
56775678
}
5679+
5680+
{
5681+
// Ticket #5121
5682+
const char code[] = "unsigned int x;"
5683+
"static const unsigned int A = 1, B = A, C = 0, D = (A), E = 0;"
5684+
"void f() {"
5685+
" unsigned int *foo = &x;"
5686+
"}";
5687+
ASSERT_EQUALS("unsigned int x ; "
5688+
"const static unsigned int A = 1 ; "
5689+
"const static unsigned int B = A ; "
5690+
"const static unsigned int C = 0 ; "
5691+
"const static unsigned int D = A ; "
5692+
"const static unsigned int E = 0 ; "
5693+
"void f ( ) { "
5694+
"unsigned int * foo ; "
5695+
"foo = & x ; "
5696+
"}",
5697+
tokenizeAndStringify(code));
5698+
}
56785699
}
56795700

56805701
void vardecl6() {

0 commit comments

Comments
 (0)