Why is this warning appearing? It's not really an assumption if I check the bounds. And how to fix?
If num_actions_to_skip
is set to 1, instead of 2, the error goes away.
Thanks
error: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Werror=strict-overflow]
cc1plus: all warnings being treated as errors
On if (loc >= 0 && loc < action_list.count()) {
const QList<QAction *> &action_list = tool_menu->actions();
static const int num_actions_to_skip = 2;
const int loc = action_list.count() - num_actions_to_skip;
if (loc >= 0 && loc < action_list.count()) {
tool_menu->insertAction(action_list.at(loc),
action);
}
It started with
Q_ASSERT_X(i >= 0 && i < p.size()
at qlist.h:454, which performs the same check, and throws this error as well, with just
tool_menu->insertAction(action_list.at(action_list.count() - 2),
action);
See Question&Answers more detail:os