diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 42b964aba..181952af8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9164,7 +9164,7 @@ void Tokenizer::findGarbageCode() const syntaxError(tok); if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|, &|= ]"))) syntaxError(tok); - if (Token::Match(tok, "[+-] [;,)]}]")) + if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;"))) syntaxError(tok); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 29ebb75a4..65ad338d4 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -397,6 +397,7 @@ private: TEST_CASE(simplifyOperatorName9); // ticket #5709 - comma operator not properly tokenized TEST_CASE(simplifyOperatorName10); // #8746 - using a::operator= TEST_CASE(simplifyOperatorName11); // #8889 + TEST_CASE(simplifyOperatorName12); // #9110 TEST_CASE(simplifyNullArray); @@ -6214,6 +6215,18 @@ private: ASSERT_EQUALS("template < typename T > void g ( S < & T :: template operator- < double > > ) { }", tokenizeAndStringify(code4)); } + void simplifyOperatorName12() { // #9110 + const char code[] = "namespace a {" + "template void operator+(b);" + "}" + "using a::operator+;"; + ASSERT_EQUALS("namespace a { " + "template < typename b > void operator+ ( b ) ; " + "} " + "using a :: operator+ ;", + tokenizeAndStringify(code)); + } + void simplifyNullArray() { ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); }