File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -473,6 +473,7 @@ std::list<Token *> TemplateSimplifier::getTemplateInstantiations(Token *tokens)
473473 if (!tok)
474474 break ;
475475 } else if (Token::Match (tok->previous (), " [({};=] %var% <" ) ||
476+ Token::Match (tok->previous (), " %type% %var% <" ) ||
476477 Token::Match (tok->tokAt (-2 ), " [,:] private|protected|public %var% <" )) {
477478
478479 // Add inner template instantiations first => go to the ">"
Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ class TestSimplifyTokens : public TestFixture {
133133 TEST_CASE (template38); // #4832 - crash on C++11 right angle brackets
134134 TEST_CASE (template39); // #4742 - freeze
135135 TEST_CASE (template40); // #5055 - template specialization outside struct
136+ TEST_CASE (template41); // #4710 - const in instantiation not handled perfectly
136137 TEST_CASE (template_unhandled);
137138 TEST_CASE (template_default_parameter);
138139 TEST_CASE (template_default_type);
@@ -2338,6 +2339,16 @@ class TestSimplifyTokens : public TestFixture {
23382339 ASSERT_EQUALS (" struct A { template < typename T > struct X { T t ; } ; } ;" , tok (code));
23392340 }
23402341
2342+ void template41 () { // #4710 - const in template instantiation not handled perfectly
2343+ const char code1[] = " template<class T> struct X { };\n "
2344+ " void f(const X<int> x) { }" ;
2345+ ASSERT_EQUALS (" void f ( const X<int> x ) { } struct X<int> { }" , tok (code1));
2346+
2347+ const char code2[] = " template<class T> T f(T t) { return t; }\n "
2348+ " int x() { return f<int>(123); }" ;
2349+ ASSERT_EQUALS (" int x ( ) { return f<int> ( 123 ) ; } int f<int> ( int t ) { return t ; }" , tok (code2));
2350+ }
2351+
23412352 void template_default_parameter () {
23422353 {
23432354 const char code[] = " template <class T, int n=3>\n "
Original file line number Diff line number Diff line change @@ -1279,7 +1279,7 @@ class TestSymbolDatabase: public TestFixture {
12791279 " public:\n "
12801280 " int f() { return C< ::D,int>::f(); }\n "
12811281 " };" );
1282- ASSERT_EQUALS (" " , errout.str ());
1282+ ASSERT_EQUALS (" [test.cpp:1]: (debug) simplifyTemplates: bailing out \n " , errout.str ());
12831283 }
12841284
12851285 void symboldatabase8 () {
You can’t perform that action at this time.
0 commit comments