fix #2963 (FP: Typedef names considered duplicate because __LINE__ not expanded)

This commit is contained in:
Robert Reif 2011-08-11 18:18:47 -04:00
parent f7b9d4d726
commit ce00d0d35e
3 changed files with 34 additions and 1 deletions

View File

@ -2118,6 +2118,29 @@ bool Tokenizer::tokenize(std::istream &code,
createTokens(code); createTokens(code);
// replace __LINE__ macro with line number
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok->str() == "__LINE__")
{
tok->str(MathLib::toString(tok->linenr()));
tok->isNumber(true);
}
}
// token concatenation
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%var%|%num% ## %var%|%num%"))
{
tok->str(tok->str() + tok->strAt(2));
tok->deleteNext();
tok->deleteNext();
if (tok->previous())
tok = tok->previous();
}
}
// simplify '[;{}] * & %any% =' to '%any% =' // simplify '[;{}] * & %any% =' to '%any% ='
simplifyMulAnd(); simplifyMulAnd();

View File

@ -263,6 +263,7 @@ private:
TEST_CASE(simplifyTypedef95); // ticket #2844 TEST_CASE(simplifyTypedef95); // ticket #2844
TEST_CASE(simplifyTypedef96); // ticket #2886 TEST_CASE(simplifyTypedef96); // ticket #2886
TEST_CASE(simplifyTypedef97); // ticket #2983 (segmentation fault) TEST_CASE(simplifyTypedef97); // ticket #2983 (segmentation fault)
TEST_CASE(simplifyTypedef98); // ticket #2963
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -5347,6 +5348,15 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef98() // ticket #2963
{
const char code[] = "#define X type ## __LINE__\n"
"typedef int X;\n"
"typedef int X;\n";
sizeof_(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {

View File

@ -3796,7 +3796,7 @@ private:
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << tok->str() << " "; ostr << tok->str() << " ";
ASSERT_EQUALS("TEST ( var , val ) var ## _ ## val = val ", ostr.str()); ASSERT_EQUALS("TEST ( var , val ) var_val = val ", ostr.str());
} }
void macrodoublesharp() void macrodoublesharp()