Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3199,9 +3199,15 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
startToken = startToken->tokAt(-2);
}

if (Token::Match(startToken->previous(), ";|{|}|=|const") &&
(!specialized && !instantiateMatch(tok2, typeParametersInDeclaration.size(), templateDeclaration.isVariadic(), isfunc ? "(" : isVar ? ";|%op%|(" : "*|&|::| %name%")))
continue;
if (Token::Match(startToken->previous(), ";|{|}|=|const")) {
const char* patternAfter = isfunc ? "(" : isVar ? ";|%op%|(" : "*|&|::| %name%";
if (!isfunc && !isVar)
if (const Token* end = startToken->next()->findClosingBracket())
if (Token::Match(end, "> (|{"))
patternAfter = "(|{";
if (!specialized && !instantiateMatch(tok2, typeParametersInDeclaration.size(), templateDeclaration.isVariadic(), patternAfter))
continue;
}

// New type..
mTypesUsedInTemplateInstantiation.clear();
Expand Down
21 changes: 21 additions & 0 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template176); // #11146
TEST_CASE(template177);
TEST_CASE(template178);
TEST_CASE(template179);
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_3);
Expand Down Expand Up @@ -4547,6 +4548,26 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS(exp2, tok(code2));
}

void template179() {
const char code[] = "template <typename T, typename C>\n" // #13498
"struct B {\n"
" int a;\n"
" int b;\n"
"};\n"
"template <typename T>\n"
"struct B<T, void> {\n"
" int a;\n"
"};\n"
"void f() {\n"
" B<int, int>{ 0, {} };\n"
"}\n";
const char exp[] = "struct B<int,int> ; "
"template < typename T > struct B < T , void > { int a ; } ; "
"void f ( ) { B<int,int> { 0 , { } } ; } "
"struct B<int,int> { int a ; int b ; } ;";
ASSERT_EQUALS(exp, tok(code));
}

void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"
Expand Down
Loading