Skip to content

Commit 5fff5da

Browse files
authored
Fixed #14129 (false positive: unusedPrivateFunction with __attribute__((unused))) (#7916)
1 parent c6f3d72 commit 5fff5da

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,11 +1342,11 @@ 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
}
1349-
if (pf->tokenDef && pf->tokenDef->isAttributeMaybeUnused()) {
1349+
if (pf->tokenDef && (pf->tokenDef->isAttributeMaybeUnused() || pf->tokenDef->isAttributeUnused())) {
13501350
privateFuncs.pop_front();
13511351
continue;
13521352
}

test/testunusedprivfunc.cpp

Lines changed: 14 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,19 @@ 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+
check("class C {\n"
901+
" __attribute__((unused)) int f();\n"
902+
"};\n"
903+
"int C::f() { return 42; }\n");
904+
ASSERT_EQUALS("", errout_str());
905+
}
906+
893907
void trailingReturn() {
894908
check("struct B { virtual void f(); };\n"
895909
"struct D : B {\n"

0 commit comments

Comments
 (0)