Skip to content
2 changes: 1 addition & 1 deletion lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ void TemplateSimplifier::expandTemplate(
--scopeCount;
if (scopeCount < 0)
break;
if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType()) {
if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType() && !Token::Match(tok3->previous(), ".|::")) {
// search for this token in the type vector
unsigned int itype = 0;
while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str())
Expand Down
41 changes: 40 additions & 1 deletion test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template178);
TEST_CASE(template179);
TEST_CASE(template180);
TEST_CASE(template181);
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 @@ -3711,7 +3712,7 @@ class TestSimplifyTemplate : public TestFixture {
"class GenericConfigurationHandler<int,std::allocator,std::list> ; "
"class TargetConfigurationHandler : public GenericConfigurationHandler<int,std::allocator,std::list> { } ; "
"class GenericConfigurationHandler<int,std::allocator,std::list> { "
"std :: list < int , std :: std :: allocator < int > > m_target_configurations ; "
"std :: list < int , std :: allocator < int > > m_target_configurations ; "
"} ;";
ASSERT_EQUALS(exp, tok(code));
}
Expand Down Expand Up @@ -4593,6 +4594,44 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void template181() {
const char code[] = "struct K { bool b; };\n" // #13747
"template<bool b>\n"
"void f(struct K* k) {\n"
" assert(b == k->b);\n"
"}\n"
"void g(struct K* k) {\n"
" f<false>(k);\n"
"}\n";
const char exp[] = "struct K { bool b ; } ; "
"void f<false> ( struct K * k ) ; "
"void g ( struct K * k ) { "
"f<false> ( k ) ; "
"} "
"void f<false> ( struct K * k ) { "
"assert ( false == k . b ) ; "
"}";
ASSERT_EQUALS(exp, tok(code));

const char code2[] = "namespace N { bool b = false; }\n" // #13759
"template<bool b>\n"
"void f() {\n"
" assert(b == N::b);\n"
"}\n"
"void g() {\n"
" f<false>();\n"
"}\n";
const char exp2[] = "namespace N { bool b ; b = false ; } "
"void f<false> ( ) ; "
"void g ( ) { "
"f<false> ( ) ; "
"} "
"void f<false> ( ) { "
"assert ( false == N :: b ) ; "
"}";
ASSERT_EQUALS(exp2, tok(code2));
}

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