diff --git a/lib/checkstl.h b/lib/checkstl.h index b9ffdc2a1..9dd5e07d5 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -186,7 +186,7 @@ public: /** @brief Look for loops that can replaced with std algorithms */ void useStlAlgorithm(); - + void checkMutexes(); private: diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c184906b3..b72ba5225 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -11161,6 +11161,22 @@ void Tokenizer::simplifyOperatorName() tok->isOperatorKeyword(true); } + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "%op% %str% %name%")) { + std::string name = tok->strAt(2); + Token * const str = tok->next(); + str->deleteNext(); + tok->insertToken("operator\"\"" + name); + tok = tok->next(); + tok->isOperatorKeyword(true); + tok->insertToken("("); + str->insertToken(")"); + Token::createMutualLinks(tok->next(), str->next()); + str->insertToken(MathLib::toString(Token::getStrLength(str))); + str->insertToken(","); + } + } + if (mSettings->debugwarnings) { const Token *tok = list.front(); diff --git a/test/teststl.cpp b/test/teststl.cpp index bec982336..677efae2a 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -165,7 +165,7 @@ private: TEST_CASE(invalidContainer); TEST_CASE(invalidContainerLoop); TEST_CASE(findInsert); - + TEST_CASE(checkMutexes); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d31179610..361c396a8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -413,6 +413,7 @@ private: TEST_CASE(simplifyOperatorName24); TEST_CASE(simplifyOperatorName25); TEST_CASE(simplifyOperatorName26); + TEST_CASE(simplifyOperatorName27); TEST_CASE(simplifyNullArray); @@ -6615,6 +6616,14 @@ private: tokenizeAndStringify(code)); } + void simplifyOperatorName27() { + const char code[] = "int operator \"\" i (const char *, int);\n" + "x = \"abc\"i;"; + ASSERT_EQUALS("int operator\"\"i ( const char * , int ) ;\n" + "x = operator\"\"i ( \"abc\" , 3 ) ;", + tokenizeAndStringify(code)); + } + void simplifyNullArray() { ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); }