Fix issue 9171: Endless recursion (#1877)

This commit is contained in:
Paul Fultz II 2019-06-10 01:22:48 -05:00 committed by Daniel Marjamäki
parent 2caea15056
commit 169510bd3a
2 changed files with 7 additions and 0 deletions

View File

@ -485,6 +485,8 @@ static bool iscpp11init(const Token * const tok)
return false;
if (Token::Match(nameToken, "else|try|do|const|override|volatile|&|&&"))
return false;
if (Token::simpleMatch(nameToken->previous(), "namespace"))
return false;
// There is no initialisation for example here: 'class Fred {};'
if (!Token::simpleMatch(endtok, "} ;"))
return true;

View File

@ -457,6 +457,7 @@ private:
TEST_CASE(findGarbageCode);
TEST_CASE(checkEnableIf);
TEST_CASE(checkTemplates);
TEST_CASE(checkNamespaces);
// #9052
TEST_CASE(noCrash1);
@ -7800,6 +7801,10 @@ private:
"int main() { using T = void (*)(a<j<F, char[]>>); }\n"))
}
void checkNamespaces() {
ASSERT_NO_THROW(tokenizeAndStringify("namespace x { namespace y { namespace z {}}}"))
}
void noCrash1() {
ASSERT_NO_THROW(tokenizeAndStringify(
"struct A {\n"