Skip to content

Commit c26752b

Browse files
committed
Fixed #14129 (false positive: unusedPrivateFunction with __attribute__((unused)))
1 parent 3e8c9d4 commit c26752b

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
@@ -1342,7 +1342,7 @@ void CheckClass::privateFunctions()
13421342

13431343
while (!privateFuncs.empty()) {
13441344
const auto& pf = privateFuncs.front();
1345-
if (pf->token->isAttributeMaybeUnused()) {
1345+
if (pf->token->isAttributeMaybeUnused() || pf->token->isAttributeUnused()) {
13461346
privateFuncs.pop_front();
13471347
continue;
13481348
}

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

@@ -890,6 +891,13 @@ class TestUnusedPrivateFunction : public TestFixture {
890891
ASSERT_EQUALS("", errout_str());
891892
}
892893

894+
void attributeUnused() {
895+
check("class C {\n"
896+
" __attribute__((unused)) int f() { return 42; }\n"
897+
"};");
898+
ASSERT_EQUALS("", errout_str());
899+
}
900+
893901
void trailingReturn() {
894902
check("struct B { virtual void f(); };\n"
895903
"struct D : B {\n"

0 commit comments

Comments
 (0)