Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (isIncrementOrDecrement && tok->astParent() && precedes(tok, tok->astOperand1()))
continue;

if (tok->str() == "=" && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))
if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))
continue;

if (tok->isName()) {
Expand Down
1 change: 0 additions & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
++indentlevel;
continue;
}
tok2 = cond->astParent()->previous();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed? If the condition is false we should be skipping the entire block.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, I see, it's a dead store. Thats a bug. I think we need to continue here and not break. I think we can fix this in a later PR.

} else if (conditionIsTrue(cond, state)) {
if (inElse)
tok2 = tok2->link()->tokAt(-2);
Expand Down
8 changes: 4 additions & 4 deletions test/testastutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class TestAstUtils : public TestFixture {
const Token * const tok = (offset < 0)
? tokenizer.list.back()->tokAt(1+offset)
: tokenizer.tokens()->tokAt(offset);
return (::isReturnScope)(tok);
return (isReturnScope)(tok);
}

void isReturnScopeTest() {
Expand Down Expand Up @@ -176,7 +176,7 @@ class TestAstUtils : public TestFixture {
tokenizer.simplifyTokens1("");
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1));
const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2));
return (::isSameExpression)(false, false, tok1, tok2, library, false, true, nullptr);
return (isSameExpression)(false, false, tok1, tok2, library, false, true, nullptr);
}

void isSameExpressionTest() {
Expand Down Expand Up @@ -214,7 +214,7 @@ class TestAstUtils : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern));
return (::isVariableChanged)(tok1, tok2, 1, false, &settings, true);
return (isVariableChanged)(tok1, tok2, 1, false, &settings, true);
}

void isVariableChangedTest() {
Expand All @@ -236,7 +236,7 @@ class TestAstUtils : public TestFixture {
std::istringstream istr(code);
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern);
return (::isVariableChangedByFunctionCall)(argtok, 0, &settings, inconclusive);
return (isVariableChangedByFunctionCall)(argtok, 0, &settings, inconclusive);
}

void isVariableChangedByFunctionCallTest() {
Expand Down
3 changes: 1 addition & 2 deletions test/testclangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,7 @@ class TestClangImport : public TestFixture {
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "sizeof (");
ASSERT(!!tok);
tok = tok->next();
// TODO ASSERT(tok->hasKnownIntValue());
// TODO ASSERT_EQUALS(10, tok->getKnownIntValue());
TODO_ASSERT_EQUALS(true, false, tok->hasKnownIntValue() && tok->getKnownIntValue() == 10);
}

void valueType1() {
Expand Down
23 changes: 23 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class TestUnusedVar : public TestFixture {
TEST_CASE(localvar61); // #9407
TEST_CASE(localvar62); // #10824
TEST_CASE(localvar63); // #6928
TEST_CASE(localvar64); // #9997
TEST_CASE(localvarloops); // loops
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
Expand Down Expand Up @@ -3484,6 +3485,28 @@ class TestUnusedVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
}

void localvar64() { // #9997
functionVariableUsage("class S {\n"
" ~S();\n"
" S* f();\n"
" S* g(int);\n"
"};\n"
"void h(S* s, bool b) {\n"
" S* p = nullptr;\n"
" S* q = nullptr;\n"
" if (b) {\n"
" p = s;\n"
" q = s->f()->g(-2);\n"
" }\n"
" else\n"
" q = s;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10]: (style) Variable 'p' is assigned a value that is never used.\n"
"[test.cpp:11]: (style) Variable 'q' is assigned a value that is never used.\n"
"[test.cpp:14]: (style) Variable 'q' is assigned a value that is never used.\n",
errout.str());
}

void localvarloops() {
// loops
functionVariableUsage("void fun(int c) {\n"
Expand Down