Skip to content
Open
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
7 changes: 7 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6935,6 +6935,13 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const
if (!parent->astOperand1())
return;

if (Token::Match(parent->astOperand1()->previous(), "auto %var% {")) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There could be variations like auto&& or auto const&.
Is the ValueType set correctly for e.g. T t{ 1 }?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is the T from a template? I would assume it would be set to whatever it is in the instantiation, but i can double check.

ValueType vt(*valuetypePtr);
vt.reference = Reference::None;
parent->astOperand1()->setValueType(new ValueType(vt));
}


const ValueType *vt1 = parent->astOperand1()->valueType();
const ValueType *vt2 = parent->astOperand2() ? parent->astOperand2()->valueType() : nullptr;

Expand Down
7 changes: 7 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class TestUnusedVar : public TestFixture {
TEST_CASE(localvar70);
TEST_CASE(localvar71);
TEST_CASE(localvar72);
TEST_CASE(localvar73);
TEST_CASE(localvarloops); // loops
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
Expand Down Expand Up @@ -4061,6 +4062,12 @@ class TestUnusedVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:4:12]: (style) Unused variable: mp [unusedVariable]\n", errout_str());
}

void localvar73() {
functionVariableUsage("struct S { S(); ~S(); };\n"
"void f() { auto s{ S() }; }\n");
Comment thread
ludviggunne marked this conversation as resolved.
ASSERT_EQUALS("", errout_str());
}

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