template simplifier: fix simplification of "< %num% %comp% %num% >" (#2214)
* template simplifier: fix simplification of "< %num% %comp% %num% >" * fix test to not fail on 32 bit platforms
This commit is contained in:
parent
0011fb5a36
commit
12f93b63a8
|
@ -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());
|
||||
|
|
|
@ -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<int N> foo = N; foo < ( 2 ) >;"));
|
||||
ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template<int N> foo = N; foo < 1 + 1 >;"));
|
||||
ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template<int N> foo = N; foo < ( 1 + 1 ) >;"));
|
||||
|
@ -4746,6 +4747,16 @@ private:
|
|||
ASSERT_EQUALS("foo<false> = false ; foo<false> ;", tok("template<bool N> foo = N; foo < ( 1 - 1) ? true : false >;"));
|
||||
}
|
||||
|
||||
void simplifyTemplateArgs2() {
|
||||
const char code[] = "template<bool T> struct a_t { static const bool t = T; };\n"
|
||||
"typedef a_t<sizeof(void*) == sizeof(char)> a;\n"
|
||||
"void foo() { bool b = a::t; }";
|
||||
const char expected[] = "struct a_t<false> ; "
|
||||
"void foo ( ) { bool b ; b = a_t<false> :: t ; } "
|
||||
"struct a_t<false> { static const bool t = false ; } ;";
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
|
||||
void template_variadic_1() { // #9144
|
||||
const char code[] = "template <typename...> struct e {};\n"
|
||||
"static_assert(sizeof(e<>) == sizeof(e<int,int>), \"\");";
|
||||
|
|
Loading…
Reference in New Issue