Skip to content

Commit 21b3cac

Browse files
committed
Add correct column number to enum tokens
1 parent 1ca1246 commit 21b3cac

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9222,6 +9222,7 @@ void Tokenizer::simplifyStructDecl()
92229222
while (!Token::Match(start, "struct|class|union|enum")) {
92239223
after->insertToken(start->str());
92249224
after = after->next();
9225+
after->column(start->column());
92259226
start->deleteThis();
92269227
}
92279228
tok = start;

test/testtokenize.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ class TestTokenizer : public TestFixture {
506506
TEST_CASE(dumpFallthrough);
507507

508508
TEST_CASE(simplifyRedundantParentheses);
509+
510+
TEST_CASE(simplifyEnum);
509511
}
510512

511513
class TokenizerTest : public Tokenizer
@@ -8810,6 +8812,16 @@ class TestTokenizer : public TestFixture {
88108812
SimpleTokenizer tokenizer(settingsDefault, *this, false);
88118813
ASSERT_NO_THROW(tokenizer.tokenize(code));
88128814
}
8815+
8816+
void simplifyEnum() {
8817+
const char code[] = "static enum {A,B} ab;";
8818+
ASSERT_EQUALS("enum Anonymous0 { A , B } ; static enum Anonymous0 ab ;", tokenizeAndStringify(code));
8819+
SimpleTokenizer tokenizer(settingsDefault, *this);
8820+
tokenizer.tokenize(code);
8821+
const Token* tok = Token::findsimplematch(tokenizer.tokens(), "static");
8822+
ASSERT(tok);
8823+
ASSERT_EQUALS(tok->column(), 1);
8824+
}
88138825
};
88148826

88158827
REGISTER_TEST(TestTokenizer)

0 commit comments

Comments
 (0)