diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bbc02b320..337e1cdb0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9446,6 +9446,11 @@ void Tokenizer::simplifyOperatorName() if (par && par->isName()) { op += par->str(); par = par->next(); + // merge namespaces eg. 'operator std :: string () const {' + if (par && par->str() == "::" && par->next() && par->next()->isName()) { + op += par->str(); + par = par->next(); + } done = false; } if (Token::Match(par, "=|.|++|--|%op%")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 1413d75c8..6c73ebf67 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -294,6 +294,8 @@ private: TEST_CASE(simplifyTypedefFunction7); TEST_CASE(simplifyTypedefFunction8); + TEST_CASE(simplifyOperator1); + TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) TEST_CASE(simplify_condition); @@ -6168,6 +6170,21 @@ private: ASSERT_EQUALS("", errout.str()); // make sure that there is no internal error } + void simplifyOperator1() { + // #3237 - error merging namespaces with operators + const char code[] = "class c {\n" + "public:\n" + " operator std::string() const;\n" + " operator string() const;\n" + "};\n"; + const char expected[] = "class c { " + "public: " + "operatorstd::string ( ) const ; " + "operatorstring ( ) const ; " + "} ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); }