diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 2a8575c2a46..c6ec6051a17 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -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()) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 155dd0aa9a8..495b65ca38f 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -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 struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_3); @@ -3711,7 +3712,7 @@ class TestSimplifyTemplate : public TestFixture { "class GenericConfigurationHandler ; " "class TargetConfigurationHandler : public GenericConfigurationHandler { } ; " "class GenericConfigurationHandler { " - "std :: list < int , std :: std :: allocator < int > > m_target_configurations ; " + "std :: list < int , std :: allocator < int > > m_target_configurations ; " "} ;"; ASSERT_EQUALS(exp, tok(code)); } @@ -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\n" + "void f(struct K* k) {\n" + " assert(b == k->b);\n" + "}\n" + "void g(struct K* k) {\n" + " f(k);\n" + "}\n"; + const char exp[] = "struct K { bool b ; } ; " + "void f ( struct K * k ) ; " + "void g ( struct K * k ) { " + "f ( k ) ; " + "} " + "void f ( struct K * k ) { " + "assert ( false == k . b ) ; " + "}"; + ASSERT_EQUALS(exp, tok(code)); + + const char code2[] = "namespace N { bool b = false; }\n" // #13759 + "template\n" + "void f() {\n" + " assert(b == N::b);\n" + "}\n" + "void g() {\n" + " f();\n" + "}\n"; + const char exp2[] = "namespace N { bool b ; b = false ; } " + "void f ( ) ; " + "void g ( ) { " + "f ( ) ; " + "} " + "void f ( ) { " + "assert ( false == N :: b ) ; " + "}"; + ASSERT_EQUALS(exp2, tok(code2)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"