File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -832,6 +832,9 @@ void TemplateSimplifier::expandTemplate(
832832 int indentlevel = 0 ;
833833 std::stack<Token *> brackets; // holds "(", "[" and "{" tokens
834834
835+ // FIXME use full name matching somehow
836+ const std::string lastName = (fullName.find (" " ) != std::string::npos) ? fullName.substr (fullName.rfind (" " )+1 ) : fullName;
837+
835838 for (; tok3; tok3 = tok3->next ()) {
836839 if (tok3->isName ()) {
837840 // search for this token in the type vector
@@ -859,8 +862,7 @@ void TemplateSimplifier::expandTemplate(
859862 }
860863 }
861864
862- // FIXME replace name..
863- const std::string lastName = (fullName.find (" " ) != std::string::npos) ? fullName.substr (fullName.rfind (" " )+1 ) : fullName;
865+ // replace name..
864866 if (Token::Match (tok3, (lastName + " !!<" ).c_str ())) {
865867 if (Token::Match (tok3->tokAt (-2 ), " > :: %name% ( )" )) {
866868 ; // Ticket #7942: Replacing for out-of-line constructors generates invalid syntax
@@ -915,6 +917,7 @@ void TemplateSimplifier::expandTemplate(
915917 // the "}" token should only be added if indentlevel is 1 but I add it always intentionally
916918 // if indentlevel ever becomes 0, cppcheck will write:
917919 // ### Error: Invalid number of character {
920+ inTemplateDefinition = false ;
918921 break ;
919922 }
920923 --indentlevel;
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ class TestSimplifyTemplate : public TestFixture {
107107 TEST_CASE (template_member_ptr); // Ticket #5786 - crash upon valid code
108108 TEST_CASE (template_namespace_1);
109109 TEST_CASE (template_namespace_2);
110+ TEST_CASE (template_namespace_3);
110111
111112 // Test TemplateSimplifier::templateParameters
112113 TEST_CASE (templateParameters);
@@ -1400,6 +1401,23 @@ class TestSimplifyTemplate : public TestFixture {
14001401 " struct X :: S < int > { } ;" , tok (code));
14011402 }
14021403
1404+ void template_namespace_3 () {
1405+ const char code[] = " namespace test16 {\n "
1406+ " template <class T> struct foo {\n "
1407+ " static void *bar();\n "
1408+ " };\n "
1409+ " void *test() { return foo<int>::bar(); }\n "
1410+ " }" ;
1411+ ASSERT_EQUALS (" namespace test16 {"
1412+ " void * test ( ) {"
1413+ " return foo < int > :: bar ( ) ;"
1414+ " } "
1415+ " } "
1416+ " struct test16 :: foo < int > {"
1417+ " static void * bar ( ) ; "
1418+ " } ;" , tok (code));
1419+ }
1420+
14031421 unsigned int templateParameters (const char code[]) {
14041422 Tokenizer tokenizer (&settings, this );
14051423
You can’t perform that action at this time.
0 commit comments