From b97f5d909e2fd7c7435e4df79d358ceae509eeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 30 Jun 2017 14:34:28 +0200 Subject: [PATCH] Fixed #6570 (False positive unusedFunction - function called from within template function) --- lib/templatesimplifier.cpp | 2 ++ test/testsimplifytemplate.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 49ec8e929..f27d2d057 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -789,6 +789,8 @@ void TemplateSimplifier::expandTemplate( } if (Token::Match(tok3, "{|(|[")) tok3 = tok3->link(); + else if (Token::simpleMatch(tok3, "namespace {")) + tok3 = tok3->tokAt(2); // Start of template.. if (tok3 == tok) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index d8dc645c4..092dc8e6f 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -105,6 +105,7 @@ private: TEST_CASE(template_constructor); // #3152 - template constructor is removed TEST_CASE(syntax_error_templates_1); TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code + TEST_CASE(template_namespace); // Test TemplateSimplifier::templateParameters TEST_CASE(templateParameters); @@ -1374,6 +1375,16 @@ private: "};"); } + void template_namespace() { + // #6570 + const char code[] = "namespace {\n" + " template void Fred(T value) { }\n" + "}\n" + "Fred(123);"; + ASSERT_EQUALS("namespace { } " + "Fred < int > ( 123 ) ; " + "void Fred < int > ( int value ) { }", tok(code)); + } unsigned int templateParameters(const char code[]) { Tokenizer tokenizer(&settings, this);