Skip to content

Commit 3885696

Browse files
committed
Fixed #14129 (false positive: unusedPrivateFunction with __attribute__((unused)))
1 parent 387d7d8 commit 3885696

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ void CheckClass::privateFunctions()
13381338

13391339
while (!privateFuncs.empty()) {
13401340
const auto& pf = privateFuncs.front();
1341-
if (pf->token->isAttributeMaybeUnused()) {
1341+
if (pf->token->isAttributeMaybeUnused() || pf->token->isAttributeUnused()) {
13421342
privateFuncs.pop_front();
13431343
continue;
13441344
}

test/testunusedprivfunc.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class TestUnusedPrivateFunction : public TestFixture {
8484

8585
TEST_CASE(templateSimplification); //ticket #6183
8686
TEST_CASE(maybeUnused);
87+
TEST_CASE(attributeUnused); // #14129
8788
TEST_CASE(trailingReturn);
8889
}
8990

@@ -884,6 +885,13 @@ class TestUnusedPrivateFunction : public TestFixture {
884885
ASSERT_EQUALS("", errout_str());
885886
}
886887

888+
void attributeUnused() {
889+
check("class C {\n"
890+
" __attribute__((unused)) int f() { return 42; }\n"
891+
"};");
892+
ASSERT_EQUALS("", errout_str());
893+
}
894+
887895
void trailingReturn() {
888896
check("struct B { virtual void f(); };\n"
889897
"struct D : B {\n"

0 commit comments

Comments
 (0)