Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,11 @@ void TemplateSimplifier::expandTemplate(
std::stack<const Token *> templates;
int scopeCount = 0;
for (; tok3; tok3 = tok3->next()) {
if (tok3->str() == "{")
if (tok3->str() == "{") {
if (isFunction && isSpecialization && inTemplateDefinition)
break;
++scopeCount;
}
else if (tok3->str() == "}")
--scopeCount;
if (scopeCount < 0)
Expand Down
27 changes: 27 additions & 0 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template181);
TEST_CASE(template182); // #13770
TEST_CASE(template183);
TEST_CASE(template184);
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 @@ -4698,6 +4699,32 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void template184() {
const char code[] = "template <typename T>\n"
"T g(T x) {\n"
" return x;\n"
"}\n"
"template <>\n"
"float g<float>(float x) {\n"
" return x + 1.0f;\n"
"}\n"
"void f(int i) {\n"
" g(i);\n"
" g(1.0f);\n"
"}\n";
const char exp[] = "float g<float> ( float x ) ; "
"template < typename T > "
"T g ( T x ) { return x ; } "
"float g<float> ( float x ) {"
" return x + 1.0f ; "
"} "
"void f ( int i ) {"
" g ( i ) ;"
" g<float> ( 1.0f ) ; "
"}";
ASSERT_EQUALS(exp, tok(code)); // TODO: instantiate g<int>(int)
}

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