From 65f571f5a9d007f9f882dc56883ad14dd9cb6c9b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:16:24 +0200 Subject: [PATCH] Fix #12615 FP syntaxError with operator= (#6295) --- lib/tokenize.cpp | 2 +- test/testgarbage.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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