Skip to content

Commit

Permalink
Fix #12363 FP unreadVariable with unknown constructor that takes a pa…
Browse files Browse the repository at this point in the history
…rameter (danmar#6305)
  • Loading branch information
chrchr-github authored Apr 18, 2024
1 parent 2ab6dc8 commit 1fa728c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,9 @@ void CheckUnusedVar::checkFunctionVariableUsage()
const bool isPointer = tok->valueType() && (tok->valueType()->pointer || tok->valueType()->type == ValueType::SMART_POINTER);

if (tok->isName()) {
if (isRaiiClass(tok->valueType(), tok->isCpp(), false))
if (isRaiiClass(tok->valueType(), tok->isCpp(), false) ||
(tok->valueType() && tok->valueType()->type == ValueType::RECORD &&
(!tok->valueType()->typeScope || !isRecordTypeWithoutSideEffects(tok->valueType()->typeScope->definedType))))
continue;
tok = tok->next();
}
Expand Down
7 changes: 7 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class TestUnusedVar : public TestFixture {
TEST_CASE(localvar68);
TEST_CASE(localvar69);
TEST_CASE(localvar70);
TEST_CASE(localvar71);
TEST_CASE(localvarloops); // loops
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
Expand Down Expand Up @@ -3906,6 +3907,12 @@ class TestUnusedVar : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void localvar71() {
functionVariableUsage("struct A { explicit A(int i); };\n" // #12363
"void f() { A a(0); }\n");
ASSERT_EQUALS("", errout_str());
}

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

0 comments on commit 1fa728c

Please sign in to comment.