Skip to content

Commit

Permalink
Fix #12476 C++ keyword compl simplified in C code
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 29, 2024
1 parent 4114205 commit 3dec110
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7518,7 +7518,7 @@ bool Tokenizer::simplifyCAlternativeTokens()
} else if (Token::Match(tok, "not|compl")) {
alt.push_back(tok);

if (Token::Match(tok->previous(), "%assign%") || Token::Match(tok->next(), "%num%")) {
if ((Token::Match(tok->previous(), "%assign%") || Token::Match(tok->next(), "%num%")) && !Token::Match(tok->next(), ".|->")) {
replaceAll = true;
continue;
}
Expand Down
9 changes: 9 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4977,6 +4977,15 @@ class TestTokenizer : public TestFixture {
"}", true, Platform::Type::Native, "test.c"));
// #10013
ASSERT_EQUALS("void f ( ) { x = ! 123 ; }", tokenizeAndStringify("void f() { x = not 123; }", true, Platform::Type::Native, "test.cpp"));

{ // #12476
const char code[] = "struct S { int a, b; };"
"void f(struct S* compl) {"
" compl->a = compl->b;"
"}";
const char exp[] = "struct S { int a ; int b ; } ; void f ( struct S * compl ) { compl . a = compl . b ; }";
ASSERT_EQUALS(exp, tokenizeAndStringify(code, true, Platform::Type::Native, "test.c"));
}
}

void simplifyRoundCurlyParentheses() {
Expand Down

0 comments on commit 3dec110

Please sign in to comment.