Skip to content

Commit af63e5f

Browse files
Fix #14783 / #14784 FN unusedVariable with templated type (default constructor, regression) (#8574)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 717566c commit af63e5f

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,6 @@ void CheckUnusedVarImpl::checkFunctionVariableUsage_iterateScopes(const Scope* c
11551155
variables.read(tok2->varId(), tok);
11561156
}
11571157
}
1158-
} else if (tok->variable() && tok->variable()->isClass() && tok->variable()->type() &&
1159-
(tok->variable()->type()->needInitialization == Type::NeedInitialization::False) &&
1160-
tok->strAt(1) == ";") {
1161-
variables.write(tok->varId(), tok);
11621158
}
11631159
}
11641160
}

test/testunusedvar.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7083,6 +7083,24 @@ class TestUnusedVar : public TestFixture {
70837083
" S<0> s;\n"
70847084
"}\n");
70857085
ASSERT_EQUALS("[test.cpp:6:10]: (style) Unused variable: s [unusedVariable]\n", errout_str());
7086+
7087+
functionVariableUsage("template <typename T>\n" // #14783
7088+
"struct A {\n"
7089+
" A() = default;\n"
7090+
"};\n"
7091+
"void f() {\n"
7092+
" A<int> a;\n"
7093+
"}\n");
7094+
ASSERT_EQUALS("[test.cpp:6:12]: (style) Unused variable: a [unusedVariable]\n", errout_str());
7095+
7096+
functionVariableUsage("template <typename T>\n" // #14784
7097+
"struct A {\n"
7098+
" A() {}\n"
7099+
"};\n"
7100+
"void f() {\n"
7101+
" A<int> a;\n"
7102+
"}\n");
7103+
ASSERT_EQUALS("[test.cpp:6:12]: (style) Unused variable: a [unusedVariable]\n", errout_str());
70867104
}
70877105

70887106
void localvarFuncPtr() {
@@ -7171,6 +7189,7 @@ class TestUnusedVar : public TestFixture {
71717189
"void f() {\n"
71727190
" Y y;\n"
71737191
"}"); // #4695
7192+
ASSERT_EQUALS("[test.cpp:6:7]: (style) Unused variable: y [unusedVariable]\n", errout_str());
71747193
}
71757194

71767195
void crash3() {

0 commit comments

Comments
 (0)