Fixed #2314 (False positive: (style) Template instantiation 'Foo' hides typedef with same name)

This commit is contained in:
Robert Reif 2010-12-16 07:48:46 +01:00 committed by Daniel Marjamäki
parent 0473473e7b
commit bf136f0123
2 changed files with 17 additions and 1 deletions

View File

@ -518,6 +518,9 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
if (!Token::Match(tok->tokAt(-2), "%type%")) if (!Token::Match(tok->tokAt(-2), "%type%"))
return false; return false;
if (!Token::Match(tok->tokAt(-3), ",|<"))
return false;
duplicateTypedefError(*tokPtr, name, "Template instantiation"); duplicateTypedefError(*tokPtr, name, "Template instantiation");
*tokPtr = end->link(); *tokPtr = end->link();
return true; return true;
@ -6602,7 +6605,7 @@ bool Tokenizer::simplifyCalculations()
} }
// Remove parentheses around number.. // Remove parentheses around number..
if (Token::Match(tok->tokAt(-2), "%any% ( %num% )") && !tok->tokAt(-2)->isName()) if (Token::Match(tok->tokAt(-2), "%any% ( %num% )") && !tok->tokAt(-2)->isName() && tok->strAt(-2) != ">")
{ {
tok = tok->previous(); tok = tok->previous();
tok->deleteThis(); tok->deleteThis();

View File

@ -221,6 +221,7 @@ private:
TEST_CASE(simplifyTypedef62); // ticket #2082 TEST_CASE(simplifyTypedef62); // ticket #2082
TEST_CASE(simplifyTypedef63); // ticket #2175 'typedef float x[3];' TEST_CASE(simplifyTypedef63); // ticket #2175 'typedef float x[3];'
TEST_CASE(simplifyTypedef64); TEST_CASE(simplifyTypedef64);
TEST_CASE(simplifyTypedef65); // ticket #2314
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4589,6 +4590,18 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef65() // ticket #2314
{
const char code[] = "typedef BAR<int> Foo; \n"
"int main() { \n"
" Foo b(0); \n"
" return b > Foo(10); \n"
"}";
const std::string actual(sizeof_(code));
ASSERT_EQUALS("; int main ( ) { BAR < int > b ( 0 ) ; return b > BAR < int > ( 10 ) ; }", actual);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {