FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix #14972 [regression] Syntax Error: AST broken, '!' doesn't have an operand. by chrchr-github · Pull Request #8791 · cppcheck-opensource/cppcheck · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5238,7 +5238,7 @@ static Token * matchMemberVarName(const Member &var, const std::list<ScopeInfo2>
{
Token *tok = matchMemberName(var, scopeInfo);
if (Token::Match(tok, "%name%")) {
if (!tok->next() || tok->strAt(1) != "(" || (tok->tokAt(2) && tok->tokAt(2)->isLiteral()))
if (!tok->next() || tok->strAt(1) != "(" || (tok->tokAt(2) && (tok->tokAt(2)->isLiteral() || tok->tokAt(2)->isOp())))

danmar Aug 22, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this looks fragile. Can you make sure it works with more than 1 parenthesis. I.e.:

struct Test {
    static bool constant;
};

bool Test::constant((!false));

I recommend a while loop that skips ( tokens.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Those parentheses are removed by simplifyRedundantParentheses(). Also, this change doesn't make the code more fragile than it already was.

return tok;
}
return nullptr;
Expand Down Expand Up @@ -5338,7 +5338,7 @@ void Tokenizer::setVarIdPass2()
}
if (!tok->next())
syntaxError(tok);
if (Token::Match(tok, "%name% (") && !(tok->tokAt(2) && tok->tokAt(2)->isLiteral()))
if (Token::Match(tok, "%name% (") && !(tok->tokAt(2) && (tok->tokAt(2)->isLiteral() || tok->tokAt(2)->isOp())))
allMemberFunctions.emplace_back(scope, usingnamespaces, tok1);
else
allMemberVars.emplace_back(scope, usingnamespaces, tok1);
Expand Down
9 changes: 9 additions & 0 deletions test/testvarid.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varidclass18);
TEST_CASE(varidclass19); // initializer list
TEST_CASE(varidclass20); // #7578: int (*p)[2]
TEST_CASE(varidclass21);
TEST_CASE(varid_classnameshaddowsvariablename); // #3990
TEST_CASE(varid_classnametemplate); // #10221

Expand Down Expand Up @@ -4021,6 +4022,14 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, tokenize(code));
}

void varidclass21() {
const char code[] = "struct T { static bool b; };\n" // #14972
"bool T::b(!false);\n";
const char expected[] = "1: struct T { static bool b@1 ; } ;\n"
"2: bool T :: b@1 ( ! false ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}

void varidenum1() {
const char code[] = "const int eStart = 6;\n"
"enum myEnum {\n"
Expand Down
Loading

Back | FazBrowse Home | New Git URL