Skip to content

Commit 26ce3f1

Browse files
Fix #13498 assertion in getParentValueTypes (danmar#7149)
1 parent e406b37 commit 26ce3f1

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/templatesimplifier.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,9 +3199,15 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
31993199
startToken = startToken->tokAt(-2);
32003200
}
32013201

3202-
if (Token::Match(startToken->previous(), ";|{|}|=|const") &&
3203-
(!specialized && !instantiateMatch(tok2, typeParametersInDeclaration.size(), templateDeclaration.isVariadic(), isfunc ? "(" : isVar ? ";|%op%|(" : "*|&|::| %name%")))
3204-
continue;
3202+
if (Token::Match(startToken->previous(), ";|{|}|=|const")) {
3203+
const char* patternAfter = isfunc ? "(" : isVar ? ";|%op%|(" : "*|&|::| %name%";
3204+
if (!isfunc && !isVar)
3205+
if (const Token* end = startToken->next()->findClosingBracket())
3206+
if (Token::Match(end, "> (|{"))
3207+
patternAfter = "(|{";
3208+
if (!specialized && !instantiateMatch(tok2, typeParametersInDeclaration.size(), templateDeclaration.isVariadic(), patternAfter))
3209+
continue;
3210+
}
32053211

32063212
// New type..
32073213
mTypesUsedInTemplateInstantiation.clear();

test/testsimplifytemplate.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class TestSimplifyTemplate : public TestFixture {
216216
TEST_CASE(template176); // #11146
217217
TEST_CASE(template177);
218218
TEST_CASE(template178);
219+
TEST_CASE(template179);
219220
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
220221
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
221222
TEST_CASE(template_specialization_3);
@@ -4547,6 +4548,26 @@ class TestSimplifyTemplate : public TestFixture {
45474548
ASSERT_EQUALS(exp2, tok(code2));
45484549
}
45494550

4551+
void template179() {
4552+
const char code[] = "template <typename T, typename C>\n" // #13498
4553+
"struct B {\n"
4554+
" int a;\n"
4555+
" int b;\n"
4556+
"};\n"
4557+
"template <typename T>\n"
4558+
"struct B<T, void> {\n"
4559+
" int a;\n"
4560+
"};\n"
4561+
"void f() {\n"
4562+
" B<int, int>{ 0, {} };\n"
4563+
"}\n";
4564+
const char exp[] = "struct B<int,int> ; "
4565+
"template < typename T > struct B < T , void > { int a ; } ; "
4566+
"void f ( ) { B<int,int> { 0 , { } } ; } "
4567+
"struct B<int,int> { int a ; int b ; } ;";
4568+
ASSERT_EQUALS(exp, tok(code));
4569+
}
4570+
45504571
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
45514572
const char code[] = "template <typename T> struct C {};\n"
45524573
"template <typename T> struct S {a};\n"

0 commit comments

Comments
 (0)