fix #2716 (Easy to reproduce crash)
This commit is contained in:
parent
0beef13794
commit
877a233145
|
@ -1476,6 +1476,22 @@ void Tokenizer::simplifyTypedef()
|
|||
}
|
||||
}
|
||||
|
||||
// check for entering a new namespace
|
||||
else if (Token::Match(tok2, "namespace %any% {"))
|
||||
{
|
||||
if (spaceInfo[classLevel].isNamespace &&
|
||||
spaceInfo[classLevel].className == tok2->next()->str())
|
||||
{
|
||||
classLevel++;
|
||||
pattern.clear();
|
||||
for (std::size_t i = classLevel; i < spaceInfo.size(); i++)
|
||||
pattern += (spaceInfo[i].className + " :: ");
|
||||
|
||||
pattern += typeName->str();
|
||||
}
|
||||
scope++;
|
||||
}
|
||||
|
||||
// check for entering a new scope
|
||||
else if (tok2->str() == "{")
|
||||
{
|
||||
|
|
|
@ -254,6 +254,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef88); // ticket #2675
|
||||
TEST_CASE(simplifyTypedef89); // ticket #2717
|
||||
TEST_CASE(simplifyTypedef90); // ticket #2718
|
||||
TEST_CASE(simplifyTypedef91); // ticket #2716
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction1);
|
||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||
|
@ -5112,6 +5113,32 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef91() // ticket #2716
|
||||
{
|
||||
const char code[] = "namespace NS {\n"
|
||||
" typedef int (*T)();\n"
|
||||
" class A {\n"
|
||||
" T f();\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"namespace NS {\n"
|
||||
" T A::f() {}\n"
|
||||
"}\n";
|
||||
const char expected[] = "namespace NS { "
|
||||
"; "
|
||||
"class A { "
|
||||
"int ( * f ( ) ) ( ) ; "
|
||||
"} ; "
|
||||
"} "
|
||||
"namespace NS { "
|
||||
"int ( * A :: f ( ) ) ( ) { } "
|
||||
"}";
|
||||
|
||||
checkSimplifyTypedef(code);
|
||||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedefFunction1()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue