Skip to content

Commit b03f36c

Browse files
committed
Ticket cppcheck-opensource#5709: Comma operator not properly tokenized.
1 parent a5aac3b commit b03f36c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7086,6 +7086,7 @@ bool Tokenizer::simplifyRedundantParentheses()
70867086

70877087
while (Token::Match(tok->previous(), "[{([,] ( !!{") &&
70887088
Token::Match(tok->link(), ") [;,])]") &&
7089+
!Token::simpleMatch(tok->tokAt(-2), "operator ,") && // Ticket #5709
70897090
!Token::findsimplematch(tok, ",", tok->link())) {
70907091
// We have "( ... )", remove the parentheses
70917092
tok->link()->deleteThis();
@@ -10161,7 +10162,7 @@ void Tokenizer::simplifyOperatorName()
1016110162
}
1016210163
done = false;
1016310164
}
10164-
if (Token::Match(par, ".|%op%")) {
10165+
if (Token::Match(par, ".|%op%|,")) {
1016510166
op += par->str();
1016610167
par = par->next();
1016710168
done = false;

test/testtokenize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ class TestTokenizer : public TestFixture {
507507
TEST_CASE(simplifyOperatorName6); // ticket #3194
508508
TEST_CASE(simplifyOperatorName7); // ticket #4619
509509
TEST_CASE(simplifyOperatorName8); // ticket #5706
510+
TEST_CASE(simplifyOperatorName9); // ticket #5709 - comma operator not properly tokenized
510511

511512
TEST_CASE(simplifyNull);
512513

@@ -8173,6 +8174,11 @@ class TestTokenizer : public TestFixture {
81738174
ASSERT_EQUALS(result6, tokenizeAndStringify(code6,false));
81748175
}
81758176

8177+
void simplifyOperatorName9() { // Ticket #5709
8178+
const char code[] = "struct R { R operator, ( R b ) ; } ;";
8179+
ASSERT_EQUALS(code, tokenizeAndStringify(code));
8180+
}
8181+
81768182
void simplifyNull() {
81778183
ASSERT_EQUALS("if ( ! p )", tokenizeAndStringify("if (p==NULL)"));
81788184
ASSERT_EQUALS("f ( NULL ) ;", tokenizeAndStringify("f(NULL);"));

0 commit comments

Comments
 (0)