Skip to content

Commit 585b9a0

Browse files
committed
Fix #14783 FN unusedVariable with templated type (default constructor, regression)
1 parent 89da2d1 commit 585b9a0

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,6 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
11601160
variables.read(tok2->varId(), tok);
11611161
}
11621162
}
1163-
} else if (tok->variable() && tok->variable()->isClass() && tok->variable()->type() &&
1164-
(tok->variable()->type()->needInitialization == Type::NeedInitialization::False) &&
1165-
tok->strAt(1) == ";") {
1166-
variables.write(tok->varId(), tok);
11671163
}
11681164
}
11691165
}

test/testunusedvar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7070,6 +7070,15 @@ class TestUnusedVar : public TestFixture {
70707070
" S<0> s;\n"
70717071
"}\n");
70727072
ASSERT_EQUALS("[test.cpp:6:10]: (style) Unused variable: s [unusedVariable]\n", errout_str());
7073+
7074+
functionVariableUsage("template <typename T>\n"
7075+
"struct A {\n"
7076+
" A() = default;\n"
7077+
"};\n"
7078+
"void f() {\n"
7079+
" A<int> a;\n"
7080+
"}\n");
7081+
ASSERT_EQUALS("[test.cpp:6:12]: (style) Unused variable: a [unusedVariable]\n", errout_str());
70737082
}
70747083

70757084
void localvarFuncPtr() {
@@ -7158,6 +7167,7 @@ class TestUnusedVar : public TestFixture {
71587167
"void f() {\n"
71597168
" Y y;\n"
71607169
"}"); // #4695
7170+
ASSERT_EQUALS("[test.cpp:6:7]: (style) Unused variable: y [unusedVariable]\n", errout_str());
71617171
}
71627172

71637173
void crash3() {

0 commit comments

Comments
 (0)