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
4 changes: 2 additions & 2 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,11 +1342,11 @@ void CheckClass::privateFunctions()

while (!privateFuncs.empty()) {
const auto& pf = privateFuncs.front();
if (pf->token->isAttributeMaybeUnused()) {
if (pf->token->isAttributeMaybeUnused() || pf->token->isAttributeUnused()) {
privateFuncs.pop_front();
continue;
}
if (pf->tokenDef && pf->tokenDef->isAttributeMaybeUnused()) {
if (pf->tokenDef && (pf->tokenDef->isAttributeMaybeUnused() || pf->tokenDef->isAttributeUnused())) {
privateFuncs.pop_front();
continue;
}
Expand Down
14 changes: 14 additions & 0 deletions test/testunusedprivfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TestUnusedPrivateFunction : public TestFixture {

TEST_CASE(templateSimplification); //ticket #6183
TEST_CASE(maybeUnused);
TEST_CASE(attributeUnused); // #14129
TEST_CASE(trailingReturn);
}

Expand Down Expand Up @@ -890,6 +891,19 @@ class TestUnusedPrivateFunction : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void attributeUnused() {
check("class C {\n"
" __attribute__((unused)) int f() { return 42; }\n"
"};");
ASSERT_EQUALS("", errout_str());

check("class C {\n"
" __attribute__((unused)) int f();\n"
"};\n"
"int C::f() { return 42; }\n");
ASSERT_EQUALS("", errout_str());
}

void trailingReturn() {
check("struct B { virtual void f(); };\n"
"struct D : B {\n"
Expand Down