Skip to content

Commit b8d483a

Browse files
Partial fix for #13747 assertion in Token::update_property_info() / fix #13759 Bad simplification of template parameter in namespace (#7446)
1 parent 4767e6a commit b8d483a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/templatesimplifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ void TemplateSimplifier::expandTemplate(
20802080
--scopeCount;
20812081
if (scopeCount < 0)
20822082
break;
2083-
if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType()) {
2083+
if (tok3->isName() && !Token::Match(tok3, "class|typename|struct") && !tok3->isStandardType() && !Token::Match(tok3->previous(), ".|::")) {
20842084
// search for this token in the type vector
20852085
unsigned int itype = 0;
20862086
while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str())

test/testsimplifytemplate.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class TestSimplifyTemplate : public TestFixture {
217217
TEST_CASE(template178);
218218
TEST_CASE(template179);
219219
TEST_CASE(template180);
220+
TEST_CASE(template181);
220221
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
221222
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
222223
TEST_CASE(template_specialization_3);
@@ -3711,7 +3712,7 @@ class TestSimplifyTemplate : public TestFixture {
37113712
"class GenericConfigurationHandler<int,std::allocator,std::list> ; "
37123713
"class TargetConfigurationHandler : public GenericConfigurationHandler<int,std::allocator,std::list> { } ; "
37133714
"class GenericConfigurationHandler<int,std::allocator,std::list> { "
3714-
"std :: list < int , std :: std :: allocator < int > > m_target_configurations ; "
3715+
"std :: list < int , std :: allocator < int > > m_target_configurations ; "
37153716
"} ;";
37163717
ASSERT_EQUALS(exp, tok(code));
37173718
}
@@ -4593,6 +4594,44 @@ class TestSimplifyTemplate : public TestFixture {
45934594
ASSERT_EQUALS(exp, tok(code));
45944595
}
45954596

4597+
void template181() {
4598+
const char code[] = "struct K { bool b; };\n" // #13747
4599+
"template<bool b>\n"
4600+
"void f(struct K* k) {\n"
4601+
" assert(b == k->b);\n"
4602+
"}\n"
4603+
"void g(struct K* k) {\n"
4604+
" f<false>(k);\n"
4605+
"}\n";
4606+
const char exp[] = "struct K { bool b ; } ; "
4607+
"void f<false> ( struct K * k ) ; "
4608+
"void g ( struct K * k ) { "
4609+
"f<false> ( k ) ; "
4610+
"} "
4611+
"void f<false> ( struct K * k ) { "
4612+
"assert ( false == k . b ) ; "
4613+
"}";
4614+
ASSERT_EQUALS(exp, tok(code));
4615+
4616+
const char code2[] = "namespace N { bool b = false; }\n" // #13759
4617+
"template<bool b>\n"
4618+
"void f() {\n"
4619+
" assert(b == N::b);\n"
4620+
"}\n"
4621+
"void g() {\n"
4622+
" f<false>();\n"
4623+
"}\n";
4624+
const char exp2[] = "namespace N { bool b ; b = false ; } "
4625+
"void f<false> ( ) ; "
4626+
"void g ( ) { "
4627+
"f<false> ( ) ; "
4628+
"} "
4629+
"void f<false> ( ) { "
4630+
"assert ( false == N :: b ) ; "
4631+
"}";
4632+
ASSERT_EQUALS(exp2, tok(code2));
4633+
}
4634+
45964635
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
45974636
const char code[] = "template <typename T> struct C {};\n"
45984637
"template <typename T> struct S {a};\n"

0 commit comments

Comments
 (0)