Skip to content

Commit 324f529

Browse files
committed
Fixed #14127 (false positive: unusedPrivateFunction with [[maybe_unused]] attribute)
1 parent 387d7d8 commit 324f529

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/checkclass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,10 @@ void CheckClass::privateFunctions()
13421342
privateFuncs.pop_front();
13431343
continue;
13441344
}
1345+
if (pf->tokenDef && pf->tokenDef->isAttributeMaybeUnused()) {
1346+
privateFuncs.pop_front();
1347+
continue;
1348+
}
13451349
// Check that all private functions are used
13461350
bool used = checkFunctionUsage(pf, scope); // Usage in this class
13471351
// Check in friend classes

test/testunusedprivfunc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,12 @@ class TestUnusedPrivateFunction : public TestFixture {
882882
" [[maybe_unused]] int f() { return 42; }\n"
883883
"};");
884884
ASSERT_EQUALS("", errout_str());
885+
886+
check("class C {\n"
887+
" [[maybe_unused]] static int f();\n"
888+
"};\n"
889+
"int C::f() { return 42; }\n");
890+
ASSERT_EQUALS("", errout_str());
885891
}
886892

887893
void trailingReturn() {

0 commit comments

Comments
 (0)