Fixed #3529 (False 'Boolean result is used in bitwise operation' in a template)

This commit is contained in:
Daniel Marjamäki 2012-02-18 08:51:09 +01:00
parent a08dab3776
commit bfb4dd6425
2 changed files with 19 additions and 2 deletions

View File

@ -236,6 +236,7 @@ void TemplateSimplifier::removeTemplates(Token *tok)
if (!Token::simpleMatch(tok, "template <"))
continue;
int indentlevel = 0;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(") {
@ -275,7 +276,16 @@ void TemplateSimplifier::removeTemplates(Token *tok)
break;
}
if (Token::Match(tok2, ">|>> class|struct %var% [,)]")) {
if (tok2->str() == "<")
++indentlevel;
else if (indentlevel >= 2 && tok2->str() == ">")
--indentlevel;
else if (indentlevel >= 3 && tok2->str() == ">>")
indentlevel -= 2;
else if (Token::Match(tok2, ">|>> class|struct %var% [,)]")) {
tok2 = tok2->next();
Token::eraseTokens(tok, tok2);
tok->deleteThis();

View File

@ -120,7 +120,8 @@ private:
TEST_CASE(template26); // #2721 - passing 'char[2]' as template parameter
TEST_CASE(template27); // #3350 - removing unused template in macro call
TEST_CASE(template28);
TEST_CASE(template29); // #3449
TEST_CASE(template29); // #3449 - don't crash for garbage code
TEST_CASE(template30); // #3529 - template < template < ..
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2152,6 +2153,12 @@ private:
ASSERT_EQUALS("struct B { } ; { } ;", sizeof_(code));
}
void template30() {
// #3529 - template < template < ..
const char code[] = "template<template<class> class A, class B> void f(){}";
ASSERT_EQUALS("", sizeof_(code));
}
void template_unhandled() {
// An unhandled template usage should be simplified..
ASSERT_EQUALS("x<int> ( ) ;", sizeof_("x<int>();"));