fix simplifyUsing hang parsing class initializer list using {} (#3146)

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
IOBYTE 2021-02-23 14:35:20 -05:00 committed by GitHub
parent a07f93f819
commit fc1cfba5e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -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);
}

View File

@ -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<rt> 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<int>;\n"
"struct A {\n"