Fixed #1651 (Tokenizer::setVarId wrong handling of return statement)
This commit is contained in:
parent
95f3533252
commit
c8c5f95721
|
@ -2282,12 +2282,14 @@ void Tokenizer::setVarId()
|
|||
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%"))
|
||||
continue;
|
||||
|
||||
// If pattern is "( %type% * %var% )" then check if it's a
|
||||
// variable declaration or a multiplication
|
||||
if (Token::Match(tok, "( %type% * %var% )") && !tok->next()->isStandardType())
|
||||
// If pattern is "( %type% *|& %var% )" then check if it's a
|
||||
// variable declaration or a multiplication / mask
|
||||
if (Token::Match(tok, "( %type% *|& %var% )") && !tok->next()->isStandardType())
|
||||
{
|
||||
if (!Token::Match(tok->previous(), "%type%"))
|
||||
continue;
|
||||
if (tok->strAt(-1) == "return")
|
||||
continue;
|
||||
if (!Token::Match(tok->tokAt(5), "const|{|;"))
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,8 @@ private:
|
|||
TEST_CASE(varid5);
|
||||
TEST_CASE(varid6);
|
||||
TEST_CASE(varid7);
|
||||
TEST_CASE(varidReturn);
|
||||
TEST_CASE(varidReturn1);
|
||||
TEST_CASE(varidReturn2);
|
||||
TEST_CASE(varid8);
|
||||
TEST_CASE(varid9);
|
||||
TEST_CASE(varid10);
|
||||
|
@ -1524,8 +1525,7 @@ private:
|
|||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
void varidReturn()
|
||||
void varidReturn1()
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"int f()\n"
|
||||
|
@ -1544,6 +1544,25 @@ private:
|
|||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
void varidReturn2()
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" unsigned long mask = (1UL << size_) - 1;\n"
|
||||
" return (abits_val_ & mask);\n"
|
||||
"}\n");
|
||||
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: void foo ( )\n"
|
||||
"2: {\n"
|
||||
"3: long mask@1 ; mask@1 = ( 1UL << size_ ) - 1 ;\n"
|
||||
"4: return ( abits_val_ & mask@1 ) ;\n"
|
||||
"5: }\n");
|
||||
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
void varid8()
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
|
|
Loading…
Reference in New Issue