diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 007ab36e3fd..f28f16e0105 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8636,7 +8636,7 @@ void Tokenizer::findGarbageCode() const syntaxError(tok); if (Token::Match(tok, "%assign% typename|class %assign%")) syntaxError(tok); - if (Token::Match(tok, "%assign% [;)}]") && (!isCPP() || !Token::Match(tok->previous(), "operator %assign% ;"))) + if (Token::Match(tok, "%assign% [;)}]") && (!isCPP() || !Token::simpleMatch(tok->previous(), "operator"))) syntaxError(tok); if (Token::Match(tok, "%cop%|=|,|[ %or%|%oror%|/|%")) syntaxError(tok); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 3726a3d2602..86e7c6c58e5 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -252,6 +252,7 @@ class TestGarbage : public TestFixture { TEST_CASE(garbageCode224); TEST_CASE(garbageCode225); TEST_CASE(garbageCode226); + TEST_CASE(garbageCode227); TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1753,6 +1754,9 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("int a() { (b((c)\\)) } {}"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("int a() { (b((c)@)) } {}"), SYNTAX); } + void garbageCode227() { // #12615 + ASSERT_NO_THROW(checkCode("f(&S::operator=);")); + } void syntaxErrorFirstToken() { ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};"), SYNTAX); // #7818