fix simplifyUsing hang parsing class initializer list using {} (#3146)
Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
parent
a07f93f819
commit
fc1cfba5e0
|
@ -1920,9 +1920,9 @@ namespace {
|
||||||
Token *tok1 = tok;
|
Token *tok1 = tok;
|
||||||
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
|
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
|
||||||
tok1 = tok1->previous();
|
tok1 = tok1->previous();
|
||||||
if (tok1->previous() && tok1->strAt(-1) == ")") {
|
if (tok1->previous() && (tok1->strAt(-1) == ")" || tok->strAt(-1) == "}")) {
|
||||||
tok1 = tok1->linkAt(-1);
|
tok1 = tok1->linkAt(-1);
|
||||||
if (Token::Match(tok1->previous(), "throw|noexcept")) {
|
if (Token::Match(tok1->previous(), "throw|noexcept (")) {
|
||||||
tok1 = tok1->previous();
|
tok1 = tok1->previous();
|
||||||
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
|
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
|
||||||
tok1 = tok1->previous();
|
tok1 = tok1->previous();
|
||||||
|
@ -1932,7 +1932,7 @@ namespace {
|
||||||
} else {
|
} else {
|
||||||
while (Token::Match(tok1->tokAt(-2), ":|, %name%")) {
|
while (Token::Match(tok1->tokAt(-2), ":|, %name%")) {
|
||||||
tok1 = tok1->tokAt(-2);
|
tok1 = tok1->tokAt(-2);
|
||||||
if (tok1->strAt(-1) != ")")
|
if (tok1->strAt(-1) != ")" && tok1->strAt(-1) != "}")
|
||||||
return;
|
return;
|
||||||
tok1 = tok1->linkAt(-1);
|
tok1 = tok1->linkAt(-1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
TEST_CASE(simplifyUsing20);
|
TEST_CASE(simplifyUsing20);
|
||||||
TEST_CASE(simplifyUsing21);
|
TEST_CASE(simplifyUsing21);
|
||||||
TEST_CASE(simplifyUsing22);
|
TEST_CASE(simplifyUsing22);
|
||||||
|
TEST_CASE(simplifyUsing23);
|
||||||
|
|
||||||
TEST_CASE(simplifyUsing8970);
|
TEST_CASE(simplifyUsing8970);
|
||||||
TEST_CASE(simplifyUsing8971);
|
TEST_CASE(simplifyUsing8971);
|
||||||
|
@ -554,6 +555,36 @@ private:
|
||||||
ASSERT_EQUALS(expected, tok(code, false)); // don't hang
|
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() {
|
void simplifyUsing8970() {
|
||||||
const char code[] = "using V = std::vector<int>;\n"
|
const char code[] = "using V = std::vector<int>;\n"
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
|
|
Loading…
Reference in New Issue