From af6e76d6239e1993ad2ff27ecac69f6e0e93a4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 25 Jun 2020 22:06:34 +0200 Subject: [PATCH] Fixed #9787 (Better handling of user defined literals) --- lib/checkstl.h | 2 +- lib/tokenize.cpp | 16 ++++++++++++++++ test/teststl.cpp | 2 +- test/testtokenize.cpp | 9 +++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) 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;")); }