Fixed #6570 (False positive unusedFunction - function called from within template function)

This commit is contained in:
Daniel Marjamäki 2017-06-30 14:34:28 +02:00
parent 22919da9a8
commit b97f5d909e
2 changed files with 13 additions and 0 deletions

View File

@ -789,6 +789,8 @@ void TemplateSimplifier::expandTemplate(
} }
if (Token::Match(tok3, "{|(|[")) if (Token::Match(tok3, "{|(|["))
tok3 = tok3->link(); tok3 = tok3->link();
else if (Token::simpleMatch(tok3, "namespace {"))
tok3 = tok3->tokAt(2);
// Start of template.. // Start of template..
if (tok3 == tok) { if (tok3 == tok) {

View File

@ -105,6 +105,7 @@ private:
TEST_CASE(template_constructor); // #3152 - template constructor is removed TEST_CASE(template_constructor); // #3152 - template constructor is removed
TEST_CASE(syntax_error_templates_1); TEST_CASE(syntax_error_templates_1);
TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code
TEST_CASE(template_namespace);
// Test TemplateSimplifier::templateParameters // Test TemplateSimplifier::templateParameters
TEST_CASE(templateParameters); TEST_CASE(templateParameters);
@ -1374,6 +1375,16 @@ private:
"};"); "};");
} }
void template_namespace() {
// #6570
const char code[] = "namespace {\n"
" template<class T> void Fred(T value) { }\n"
"}\n"
"Fred<int>(123);";
ASSERT_EQUALS("namespace { } "
"Fred < int > ( 123 ) ; "
"void Fred < int > ( int value ) { }", tok(code));
}
unsigned int templateParameters(const char code[]) { unsigned int templateParameters(const char code[]) {
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);