diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 658f6e44a..03318aed9 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -934,8 +934,12 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok) // should be moved away. bool TemplateSimplifier::simplifyCalculations(Token *_tokens) { - bool ret = false; + bool ret = false, goback = false; for (Token *tok = _tokens; tok; tok = tok->next()) { + if (goback) { + tok = tok->previous(); + goback = false; + } // Remove parentheses around variable.. // keep parentheses here: dynamic_cast(p); // keep parentheses here: A operator * (int); @@ -1102,6 +1106,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) tok->str(result); tok->deleteNext(2); ret = true; + goback = true; } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index d24e7d3a5..a9c0f7fa7 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -136,6 +136,7 @@ private: TEST_CASE(template41); // #4710 - const in instantiation not handled perfectly TEST_CASE(template42); // #4878 - variadic templates TEST_CASE(template43); // #5097 - assert due to '>>' not treated as end of template instantiation + TEST_CASE(template44); // #5297 - TemplateSimplifier::simplifyCalculations not eager enough TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2379,6 +2380,16 @@ private: tok(code); // Don't assert } + void template44() { // #5297 + tok("template struct StackContainer {" + " void foo(int i) {" + " if (0 >= 1 && i<0) {}" + " }" + "};" + "template class ZContainer : public StackContainer {};" + "struct FGSTensor {};" + "class FoldedZContainer : public ZContainer {};"); + } void template_default_parameter() { {