fix #2963 (FP: Typedef names considered duplicate because __LINE__ not expanded)
This commit is contained in:
parent
f7b9d4d726
commit
ce00d0d35e
|
@ -2118,6 +2118,29 @@ bool Tokenizer::tokenize(std::istream &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% ='
|
||||
simplifyMulAnd();
|
||||
|
||||
|
|
|
@ -263,6 +263,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef95); // ticket #2844
|
||||
TEST_CASE(simplifyTypedef96); // ticket #2886
|
||||
TEST_CASE(simplifyTypedef97); // ticket #2983 (segmentation fault)
|
||||
TEST_CASE(simplifyTypedef98); // ticket #2963
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction1);
|
||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||
|
@ -5347,6 +5348,15 @@ private:
|
|||
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()
|
||||
{
|
||||
{
|
||||
|
|
|
@ -3796,7 +3796,7 @@ private:
|
|||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue