diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index bf2ff16613c..3b0ab925cd1 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1342,6 +1342,10 @@ void CheckClass::privateFunctions() privateFuncs.pop_front(); continue; } + if (pf->tokenDef && pf->tokenDef->isAttributeMaybeUnused()) { + privateFuncs.pop_front(); + continue; + } // Check that all private functions are used bool used = checkFunctionUsage(pf, scope); // Usage in this class // Check in friend classes diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 8afbf6ff6e5..537385d60aa 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -882,6 +882,12 @@ class TestUnusedPrivateFunction : public TestFixture { " [[maybe_unused]] int f() { return 42; }\n" "};"); ASSERT_EQUALS("", errout_str()); + + check("class C {\n" + " [[maybe_unused]] static int f();\n" + "};\n" + "int C::f() { return 42; }\n"); + ASSERT_EQUALS("", errout_str()); } void trailingReturn() {