From 2d7fedbb499c00996e1c4300a9bd7413b884ca60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Dec 2017 15:41:32 +0100 Subject: [PATCH] Try to fix Travis --- lib/templatesimplifier.cpp | 7 +++++-- test/testsimplifytemplate.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5c8cb4148..142c28509 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -832,6 +832,9 @@ void TemplateSimplifier::expandTemplate( int indentlevel = 0; std::stack brackets; // holds "(", "[" and "{" tokens + // FIXME use full name matching somehow + const std::string lastName = (fullName.find(" ") != std::string::npos) ? fullName.substr(fullName.rfind(" ")+1) : fullName; + for (; tok3; tok3 = tok3->next()) { if (tok3->isName()) { // search for this token in the type vector @@ -859,8 +862,7 @@ void TemplateSimplifier::expandTemplate( } } - // FIXME replace name.. - const std::string lastName = (fullName.find(" ") != std::string::npos) ? fullName.substr(fullName.rfind(" ")+1) : fullName; + // replace name.. if (Token::Match(tok3, (lastName + " !!<").c_str())) { if (Token::Match(tok3->tokAt(-2), "> :: %name% ( )")) { ; // Ticket #7942: Replacing for out-of-line constructors generates invalid syntax @@ -915,6 +917,7 @@ void TemplateSimplifier::expandTemplate( // the "}" token should only be added if indentlevel is 1 but I add it always intentionally // if indentlevel ever becomes 0, cppcheck will write: // ### Error: Invalid number of character { + inTemplateDefinition = false; break; } --indentlevel; diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 1e9b663b0..d669d2ff9 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -107,6 +107,7 @@ private: TEST_CASE(template_member_ptr); // Ticket #5786 - crash upon valid code TEST_CASE(template_namespace_1); TEST_CASE(template_namespace_2); + TEST_CASE(template_namespace_3); // Test TemplateSimplifier::templateParameters TEST_CASE(templateParameters); @@ -1400,6 +1401,23 @@ private: "struct X :: S < int > { } ;", tok(code)); } + void template_namespace_3() { + const char code[] = "namespace test16 {\n" + " template struct foo {\n" + " static void *bar();\n" + " };\n" + " void *test() { return foo::bar(); }\n" + "}"; + ASSERT_EQUALS("namespace test16 {" + " void * test ( ) {" + " return foo < int > :: bar ( ) ;" + " } " + "} " + "struct test16 :: foo < int > {" + " static void * bar ( ) ; " + "} ;", tok(code)); + } + unsigned int templateParameters(const char code[]) { Tokenizer tokenizer(&settings, this);