diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 6742aa041..cf9cdf1a6 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1653,7 +1653,7 @@ void TemplateSimplifier::expandTemplate( } dst->insertToken(";", "", true); - if (isVariable) + if (isVariable || isFunction) simplifyTemplateArgs(dstStart, dst); } @@ -2344,6 +2344,27 @@ bool TemplateSimplifier::simplifyCalculations(Token* frontToken, Token *backToke tok->str(MathLib::toString(MathLib::toLongNumber(tok->str()))); } + if (validTokenEnd(bounded, tok, backToken, 5) && + Token::Match(tok, "decltype ( %type% { } )")) { + tok->deleteThis(); + tok->deleteThis(); + tok->deleteNext(); + tok->deleteNext(); + tok->deleteNext(); + ret = true; + } + + if (validTokenEnd(bounded, tok, backToken, 2) && + Token::Match(tok, "char|short|int|long { }")) { + tok->str("0"); // FIXME add type suffix + tok->isSigned(false); + tok->isUnsigned(false); + tok->isLong(false); + tok->deleteNext(); + tok->deleteNext(); + ret = true; + } + if (tok && tok->isNumber()) { if (validTokenEnd(bounded, tok, backToken, 2) && simplifyNumericCalculations(tok)) { @@ -3250,7 +3271,7 @@ void TemplateSimplifier::simplifyTemplates( } } - // TODO: 3 is not the ideal number of loops. + // TODO: 4 is not the ideal number of loops. // We should loop until the number of declarations is 0 but we can't // do that until we instantiate unintstantiated templates with their symbolic types. // That will allow the uninstantiated template code to be removed from the symbol database. @@ -3258,7 +3279,7 @@ void TemplateSimplifier::simplifyTemplates( // the uninstantiated template code in the symbol database can't be removed until #8768 // is fixed. - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 4; ++i) { if (i) { // it may take more than one pass to simplify type aliases while (mTokenizer->simplifyUsing()) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 54ccab07f..befb646cb 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -152,6 +152,7 @@ private: TEST_CASE(template112); // #9146 syntax error TEST_CASE(template113); TEST_CASE(template114); // #9155 + TEST_CASE(template115); // #9153 TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -1848,8 +1849,8 @@ private: "auto d() -> typename a::e {\n" " d();\n" "}"; - const char exp[] = "auto d ( ) . a < decltype ( int { } ) > :: e ; " - "auto d ( ) . a < decltype ( int { } ) > :: e { " + const char exp[] = "auto d ( ) . a < int > :: e ; " + "auto d ( ) . a < int > :: e { " "d ( ) ; " "}"; ASSERT_EQUALS(exp, tok(code)); @@ -2696,6 +2697,31 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template115() { // #9153 + const char code[] = "namespace {\n" + " namespace b {\n" + " template struct B { using B::d; };\n" + " }\n" + " template using e = typename b::B;\n" + " namespace b {\n" + " template struct f {};\n" + " }\n" + " template using g = b::f>;\n" + "}\n" + "g g1;"; + const char exp[] = "namespace { " + "namespace b { " + "struct B<0> ; " + "} " + "namespace b { " + "struct f> ; " + "} " + "} " + "b :: f> g1 ; struct b :: B<0> { using B<0> :: d ; } ; " + "struct b :: f> { } ;"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"