Skip to content

Commit 9a500c8

Browse files
Fix #14972 [regression] Syntax Error: AST broken, '!' doesn't have an operand. (#8791)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 0ff234b commit 9a500c8

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5244,7 +5244,7 @@ static Token * matchMemberVarName(const Member &var, const std::list<ScopeInfo2>
52445244
{
52455245
Token *tok = matchMemberName(var, scopeInfo);
52465246
if (Token::Match(tok, "%name%")) {
5247-
if (!tok->next() || tok->strAt(1) != "(" || (tok->tokAt(2) && tok->tokAt(2)->isLiteral()))
5247+
if (!tok->next() || tok->strAt(1) != "(" || (tok->tokAt(2) && (tok->tokAt(2)->isLiteral() || tok->tokAt(2)->isOp())))
52485248
return tok;
52495249
}
52505250
return nullptr;
@@ -5344,7 +5344,7 @@ void Tokenizer::setVarIdPass2()
53445344
}
53455345
if (!tok->next())
53465346
syntaxError(tok);
5347-
if (Token::Match(tok, "%name% (") && !(tok->tokAt(2) && tok->tokAt(2)->isLiteral()))
5347+
if (Token::Match(tok, "%name% (") && !(tok->tokAt(2) && (tok->tokAt(2)->isLiteral() || tok->tokAt(2)->isOp())))
53485348
allMemberFunctions.emplace_back(scope, usingnamespaces, tok1);
53495349
else
53505350
allMemberVars.emplace_back(scope, usingnamespaces, tok1);

test/testvarid.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class TestVarID : public TestFixture {
222222
TEST_CASE(varidclass18);
223223
TEST_CASE(varidclass19); // initializer list
224224
TEST_CASE(varidclass20); // #7578: int (*p)[2]
225+
TEST_CASE(varidclass21);
225226
TEST_CASE(varid_classnameshaddowsvariablename); // #3990
226227
TEST_CASE(varid_classnametemplate); // #10221
227228

@@ -4018,6 +4019,14 @@ class TestVarID : public TestFixture {
40184019
ASSERT_EQUALS(expected, tokenize(code));
40194020
}
40204021

4022+
void varidclass21() {
4023+
const char code[] = "struct T { static bool b; };\n" // #14972
4024+
"bool T::b(!false);\n";
4025+
const char expected[] = "1: struct T { static bool b@1 ; } ;\n"
4026+
"2: bool T :: b@1 ( ! false ) ;\n";
4027+
ASSERT_EQUALS(expected, tokenize(code));
4028+
}
4029+
40214030
void varidenum1() {
40224031
const char code[] = "const int eStart = 6;\n"
40234032
"enum myEnum {\n"

0 commit comments

Comments
 (0)