On GCC 7 I have enabled most of all warnings on Qt creator 4.9. Now I have a switch statement which covers all enumeration values. If I add a default: I get a warning (from Qt creator):
warning: default label in switch which covers all enumeration values
If I remove the default: I get another warning (from GCC):
error: this statement may fall through [-Werror=implicit-fallthrough=]
}
^
error: all warnings being treated as errors
What am I supposed to do? Turn off warnings? They are useful, I don't want to turn off any of them, but Wimplicit-fallthrough seems to be faulty.
[[fallthrough]] doesn't help because the cases end with a return thus I get (from Qt creator):
warning: fallthrough annotation in unreachable code
__attribute__ ((fallthrough)) didn't do anything either. Neither did /* FALLTHRU */ or [[gnu::fallthrough]] or // fall through. Presumably because of -pedantic?
Example:
enum class E {a, b, c};
QVariant fun(E e) {
switch (e) {
case E::a: return "something";
case E::b: return "something_else";
case E::c: return "something_different";
// default: return QVariant{};
// Do I add a default:? What do I add here?
}
}
Hopefully the things I've tried shows that my question is not a duplicate of this or this or other similar questions because they don't solve my problem.