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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/tokenize.cpp
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 danmar Aug 22, 2026

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.

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.

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
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