Merge pull request #303 from simartin/ticket_5297

Ticket #5297: simplifyCalculations should pass once more on simplified tokens
This commit is contained in:
Daniel Marjamäki 2014-05-10 10:18:29 +02:00
commit 4e2c0617d3
2 changed files with 17 additions and 1 deletions

View File

@ -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<Fred *>(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;
}
}
}

View File

@ -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<class T> struct StackContainer {"
" void foo(int i) {"
" if (0 >= 1 && i<0) {}"
" }"
"};"
"template<class T> class ZContainer : public StackContainer<T> {};"
"struct FGSTensor {};"
"class FoldedZContainer : public ZContainer<FGSTensor> {};");
}
void template_default_parameter() {
{