Skip to content

Commit 42068a3

Browse files
committed
Fixed cppcheck-opensource#4767 (segmentation fault in expand template)
1 parent 287782a commit 42068a3

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ void TemplateSimplifier::expandTemplate(
630630
std::list<Token *> &templateInstantiations)
631631
{
632632
for (const Token *tok3 = tokenlist.front(); tok3; tok3 = tok3->next()) {
633-
if (tok3->str() == "{" || tok3->str() == "(")
633+
if (tok3->str() == "{" || tok3->str() == "(" || tok3->str() == "[")
634634
tok3 = tok3->link();
635635

636636
// Start of template..

test/testsimplifytokens.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ class TestSimplifyTokens : public TestFixture {
18941894
"{\n"
18951895
"public:\n"
18961896
" static AA<T> create(T* newObject);\n"
1897+
" static int size();\n"
18971898
"};\n"
18981899
"\n"
18991900
"class CC { public: CC(AA<BB>, int) {} };\n"
@@ -1906,7 +1907,9 @@ class TestSimplifyTokens : public TestFixture {
19061907
"\n"
19071908
"XX::XX():\n"
19081909
" y(AA<CC>::create(new CC(AA<BB>(), 0)))\n"
1909-
" {}\n";
1910+
" {}\n"
1911+
"\n"
1912+
"int yy[AA<CC>::size()];";
19101913

19111914
// Just run it and check that there are not assertions.
19121915
tok(code);

0 commit comments

Comments
 (0)