Skip to content

Commit d3e79b7

Browse files
committed
cppcheck-opensource#8051 Add regression test. Issue got fixed before.
1 parent e8d1e4b commit d3e79b7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

test/testsimplifytemplate.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class TestSimplifyTemplate : public TestFixture {
9696
TEST_CASE(template56); // #7117 - const ternary operator simplification as template parameter
9797
TEST_CASE(template57); // #7891
9898
TEST_CASE(template58); // #6021 - use after free (deleted tokens in simplifyCalculations)
99+
TEST_CASE(template59); // #8051 - TemplateSimplifier::simplifyTemplateInstantiation failure
99100
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
100101
TEST_CASE(template_unhandled);
101102
TEST_CASE(template_default_parameter);
@@ -1065,6 +1066,32 @@ class TestSimplifyTemplate : public TestFixture {
10651066
ASSERT_EQUALS(exp, tok(code));
10661067
}
10671068

1069+
void template59() { // #8051
1070+
const char code[] = "template<int N>\n"
1071+
"struct Factorial {\n"
1072+
" enum FacHelper { value = N * Factorial<N - 1>::value };\n"
1073+
"};\n"
1074+
"template <>\n"
1075+
"struct Factorial<0> {\n"
1076+
" enum FacHelper { value = 1 };\n"
1077+
"};\n"
1078+
"template<int DiagonalDegree>\n"
1079+
"int diagonalGroupTest() {\n"
1080+
" return Factorial<DiagonalDegree>::value;\n"
1081+
"}\n"
1082+
"int main () {\n"
1083+
" return diagonalGroupTest<4>();\n"
1084+
"}";
1085+
const char exp[] = "struct Factorial < 0 > { enum FacHelper { value = 1 } ; } ; "
1086+
"int main ( ) { return diagonalGroupTest < 4 > ( ) ; } "
1087+
"int diagonalGroupTest < 4 > ( ) { return Factorial < 4 > :: value ; } "
1088+
"struct Factorial < 4 > { enum FacHelper { value = 4 * Factorial < 3 > :: value } ; } ; "
1089+
"struct Factorial < 3 > { enum FacHelper { value = 3 * Factorial < 2 > :: value } ; } ; "
1090+
"struct Factorial < 2 > { enum FacHelper { value = 2 * Factorial < 1 > :: value } ; } ; "
1091+
"struct Factorial < 1 > { enum FacHelper { value = Factorial < 0 > :: value } ; } ;";
1092+
ASSERT_EQUALS(exp, tok(code));
1093+
}
1094+
10681095
void template_enum() {
10691096
const char code1[] = "template <class T>\n"
10701097
"struct Unconst {\n"

0 commit comments

Comments
 (0)