diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 4c8555fd0..dfe299c74 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2362,7 +2362,7 @@ void TemplateSimplifier::simplifyTemplateArgs(Token *start, Token *end) } else if (Token::Match(tok, "%num% %comp% %num%") && MathLib::isInt(tok->str()) && MathLib::isInt(tok->strAt(2))) { - if ((Token::Match(tok->previous(), "(|&&|%oror%|,") || tok->previous() == start) && + if ((Token::Match(tok->previous(), "(|&&|%oror%|,") || tok == start) && (Token::Match(tok->tokAt(3), ")|&&|%oror%|?") || tok->tokAt(3) == end)) { const MathLib::bigint op1(MathLib::toLongNumber(tok->str())); const std::string &cmp(tok->next()->str()); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index f54fda3af..5ae0e2eec 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -233,7 +233,8 @@ private: TEST_CASE(templateTypeDeduction1); // #8962 TEST_CASE(templateTypeDeduction2); - TEST_CASE(simplifyTemplateArgs); + TEST_CASE(simplifyTemplateArgs1); + TEST_CASE(simplifyTemplateArgs2); TEST_CASE(template_variadic_1); // #9144 @@ -4729,7 +4730,7 @@ private: TODO_ASSERT_EQUALS(expected, actual, tok(code)); } - void simplifyTemplateArgs() { + void simplifyTemplateArgs1() { ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template foo = N; foo < ( 2 ) >;")); ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template foo = N; foo < 1 + 1 >;")); ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template foo = N; foo < ( 1 + 1 ) >;")); @@ -4746,6 +4747,16 @@ private: ASSERT_EQUALS("foo = false ; foo ;", tok("template foo = N; foo < ( 1 - 1) ? true : false >;")); } + void simplifyTemplateArgs2() { + const char code[] = "template struct a_t { static const bool t = T; };\n" + "typedef a_t a;\n" + "void foo() { bool b = a::t; }"; + const char expected[] = "struct a_t ; " + "void foo ( ) { bool b ; b = a_t :: t ; } " + "struct a_t { static const bool t = false ; } ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void template_variadic_1() { // #9144 const char code[] = "template struct e {};\n" "static_assert(sizeof(e<>) == sizeof(e), \"\");";