[Bug c++/53479] Control flow analysis reports warnings in switch over an enum class even if all possible values have their branches
db0451 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Sep 10 15:29:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53479
DB <db0451 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |db0451 at gmail dot com
--- Comment #5 from DB <db0451 at gmail dot com> ---
Sorry to wake the dead, but I'm wondering whether anyone has ever considered
adding an opt-out for this diagnostic, or whether there's any other way to
issue the following hint to g++:
> "Believe me: you will only ever get one of these values, so don't worry about it"
Of course a malicious and/or absent-minded caller could pass in a value that
the switch doesn't handle and invoke UB, but what about codebases that don't
let in such callers? Should they have to artificially add a
default/return/abort/whatever just to keep their build log readable?
Interestingly, Clang is silent if you handle all your enum (including
non-class) cases (and if you don't, says "control **may** reach end of non-void
function [-Wreturn-type]") - which, yeah, seems nice initially - but arguably
is a worse default, due to the aforementioned malicious caller and what
Jonathan explained.
So, I feel GCC could do one better by - quite rightly! - defaulting to warning
about such callers - but, crucially, allowing the warning to be disabled by
competent ones (willing to take the blame if they pass a duff value later)
Anyway, just some idle thoughts and questions. I understand the current
reasoning and don't disagree with the default, but think there's a potential
gain here too.
More information about the Gcc-bugs
mailing list