Skip to content

Commit 150aacf

Browse files
Fix #12312 FP variableScope with templates in namespace (#6167)
1 parent f147d5c commit 150aacf

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ void TemplateSimplifier::expandTemplate(
21732173
addNamespace(templateDeclaration, tok3);
21742174
}
21752175
mTokenList.addtoken(newName, tok3);
2176-
} else if (!Token::Match(tok3->next(), ":|{|=|;|[|]"))
2176+
} else if (!Token::Match(tok3->next(), "[:{=;[]),]"))
21772177
tok3->str(newName);
21782178
continue;
21792179
}

test/testsimplifytemplate.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class TestSimplifyTemplate : public TestFixture {
219219
TEST_CASE(template178);
220220
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
221221
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
222+
TEST_CASE(template_specialization_3);
222223
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
223224
TEST_CASE(template_unhandled);
224225
TEST_CASE(template_default_parameter);
@@ -4564,6 +4565,24 @@ class TestSimplifyTemplate : public TestFixture {
45644565
ASSERT_EQUALS(exp, tok(code));
45654566
}
45664567

4568+
void template_specialization_3() {
4569+
const char code[] = "namespace N {\n" // #12312
4570+
" template <typename T>\n"
4571+
" bool equal(const T&);\n"
4572+
" template <>\n"
4573+
" bool equal<int>(const int&) { return false; }\n"
4574+
"}\n"
4575+
"void f(bool equal, int i) { if (equal) {} }\n";
4576+
const char exp[] = "namespace N { "
4577+
"bool equal<int> ( const int & ) ; "
4578+
"template < typename T > "
4579+
"bool equal ( const T & ) ; "
4580+
"bool equal<int> ( const int & ) { return false ; } "
4581+
"} "
4582+
"void f ( bool equal , int i ) { if ( equal ) { } }";
4583+
ASSERT_EQUALS(exp, tok(code));
4584+
}
4585+
45674586
void template_enum() {
45684587
const char code1[] = "template <class T>\n"
45694588
"struct Unconst {\n"

0 commit comments

Comments
 (0)