diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b0497c314..356937879 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1920,9 +1920,9 @@ namespace { Token *tok1 = tok; while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept")) tok1 = tok1->previous(); - if (tok1->previous() && tok1->strAt(-1) == ")") { + if (tok1->previous() && (tok1->strAt(-1) == ")" || tok->strAt(-1) == "}")) { tok1 = tok1->linkAt(-1); - if (Token::Match(tok1->previous(), "throw|noexcept")) { + if (Token::Match(tok1->previous(), "throw|noexcept (")) { tok1 = tok1->previous(); while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept")) tok1 = tok1->previous(); @@ -1932,7 +1932,7 @@ namespace { } else { while (Token::Match(tok1->tokAt(-2), ":|, %name%")) { tok1 = tok1->tokAt(-2); - if (tok1->strAt(-1) != ")") + if (tok1->strAt(-1) != ")" && tok1->strAt(-1) != "}") return; tok1 = tok1->linkAt(-1); } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 3018b99a7..f68fe902b 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -69,6 +69,7 @@ private: TEST_CASE(simplifyUsing20); TEST_CASE(simplifyUsing21); TEST_CASE(simplifyUsing22); + TEST_CASE(simplifyUsing23); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -554,6 +555,36 @@ private: ASSERT_EQUALS(expected, tok(code, false)); // don't hang } + void simplifyUsing23() { + const char code[] = "class cmcch {\n" + "public:\n" + " cmcch(icmsp const& icm, Rtnf&& rtnf = {});\n" + "private:\n" + " using escs = aa::bb::cc::dd::ee;\n" + "private:\n" + " icmsp m_icm;\n" + " mutable std::atomic m_rt;\n" + "};\n" + "cmcch::cmcch(cmcch::icmsp const& icm, Rtnf&& rtnf)\n" + " : m_icm(icm)\n" + " , m_rt{rt::UNKNOWN_} {\n" + " using escs = yy::zz::aa::bb::cc::dd::ee;\n" + "}"; + const char expected[] = "class cmcch { " + "public: " + "cmcch ( const icmsp & icm , Rtnf && rtnf = { } ) ; " + "private: " + "private: " + "icmsp m_icm ; " + "mutable std :: atomic < rt > m_rt ; " + "} ; " + "cmcch :: cmcch ( const cmcch :: icmsp & icm , Rtnf && rtnf ) " + ": m_icm ( icm ) " + ", m_rt { rt :: UNKNOWN_ } { " + "}"; + ASSERT_EQUALS(expected, tok(code, false)); // don't hang + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n"