From f53ff27b712ec942c1c36b5b1e116bf024d4d71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Mar 2011 21:15:42 +0100 Subject: [PATCH] Tokenizer::simplifyTemplates: better handling of '(foo())'. Ticket: #2631 --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 82e0d05a5..c028b3388 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2714,7 +2714,7 @@ std::list Tokenizer::simplifyTemplatesGetTemplateInstantiations() if (!tok) break; } - else if (Token::Match(tok->previous(), "[{};=] %var% <") || + else if (Token::Match(tok->previous(), "[({};=] %var% <") || Token::Match(tok->tokAt(-2), "[,:] private|protected|public %var% <")) { if (templateParameters(tok->next())) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 96ec83945..37f484c6b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -113,6 +113,7 @@ private: TEST_CASE(template20); TEST_CASE(template21); TEST_CASE(template22); + TEST_CASE(template23); TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2025,6 +2026,22 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void template23() + { + const char code[] = "template void foo() { }\n" + "void bar() {\n" + " std::cout << (foo());\n" + "}"; + + const std::string expected("; " + "void bar ( ) {" + " std :: cout << ( foo ( ) ) ; " + "} " + "void foo ( ) { }"); + + ASSERT_EQUALS(expected, sizeof_(code)); + } + void template_unhandled() {