Respect [[maybe_unused]] in unusedPrivateFunction (#4579)
This commit is contained in:
parent
7f74aad8e2
commit
4e75c08f58
|
@ -1273,19 +1273,24 @@ void CheckClass::privateFunctions()
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!privateFuncs.empty()) {
|
while (!privateFuncs.empty()) {
|
||||||
|
const auto& pf = privateFuncs.front();
|
||||||
|
if (pf->retDef && pf->retDef->isAttributeMaybeUnused()) {
|
||||||
|
privateFuncs.pop_front();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Check that all private functions are used
|
// Check that all private functions are used
|
||||||
bool used = checkFunctionUsage(privateFuncs.front(), scope); // Usage in this class
|
bool used = checkFunctionUsage(pf, scope); // Usage in this class
|
||||||
// Check in friend classes
|
// Check in friend classes
|
||||||
const std::vector<Type::FriendInfo>& friendList = scope->definedType->friendList;
|
const std::vector<Type::FriendInfo>& friendList = scope->definedType->friendList;
|
||||||
for (int i = 0; i < friendList.size() && !used; i++) {
|
for (int i = 0; i < friendList.size() && !used; i++) {
|
||||||
if (friendList[i].type)
|
if (friendList[i].type)
|
||||||
used = checkFunctionUsage(privateFuncs.front(), friendList[i].type->classScope);
|
used = checkFunctionUsage(pf, friendList[i].type->classScope);
|
||||||
else
|
else
|
||||||
used = true; // Assume, it is used if we do not see friend class
|
used = true; // Assume, it is used if we do not see friend class
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!used)
|
if (!used)
|
||||||
unusedPrivateFunctionError(privateFuncs.front()->tokenDef, scope->className, privateFuncs.front()->name());
|
unusedPrivateFunctionError(pf->tokenDef, scope->className, pf->name());
|
||||||
|
|
||||||
privateFuncs.pop_front();
|
privateFuncs.pop_front();
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ private:
|
||||||
TEST_CASE(staticVariable); //ticket #5566
|
TEST_CASE(staticVariable); //ticket #5566
|
||||||
|
|
||||||
TEST_CASE(templateSimplification); //ticket #6183
|
TEST_CASE(templateSimplification); //ticket #6183
|
||||||
|
TEST_CASE(maybeUnused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -874,6 +875,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void maybeUnused() {
|
||||||
|
check("class C {\n"
|
||||||
|
" [[maybe_unused]] int f() { return 42; }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestUnusedPrivateFunction)
|
REGISTER_TEST(TestUnusedPrivateFunction)
|
||||||
|
|
Loading…
Reference in New Issue