Skip to content

Commit 3e8c9d4

Browse files
authored
Fixed #14127 (false positive: unusedPrivateFunction with [[maybe_unused]] attribute) (danmar#7917)
1 parent 6798a55 commit 3e8c9d4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/checkclass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,10 @@ void CheckClass::privateFunctions()
13461346
privateFuncs.pop_front();
13471347
continue;
13481348
}
1349+
if (pf->tokenDef && pf->tokenDef->isAttributeMaybeUnused()) {
1350+
privateFuncs.pop_front();
1351+
continue;
1352+
}
13491353
// Check that all private functions are used
13501354
bool used = checkFunctionUsage(pf, scope); // Usage in this class
13511355
// 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)