This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/65864] New: Consider emitting -Wswitch-bool less aggressively?
- From: "ktkachov at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 23 Apr 2015 17:18:58 +0000
- Subject: [Bug c/65864] New: Consider emitting -Wswitch-bool less aggressively?
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65864
Bug ID: 65864
Summary: Consider emitting -Wswitch-bool less aggressively?
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ktkachov at gcc dot gnu.org
CC: mpolacek at gcc dot gnu.org
Consider the following function from the linux kernel (fs/nfs/nfs4proc.c):
int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
struct nfs_fsinfo *info,
bool auth_probe)
{
int status;
switch (auth_probe) {
case false:
status = nfs4_lookup_root(server, fhandle, info);
if (status != -NFS4ERR_WRONGSEC)
break;
default:
status = nfs4_do_find_root_sec(server, fhandle, info);
}
if (status == 0)
status = nfs4_server_capabilities(server, fhandle);
if (status == 0)
status = nfs4_do_fsinfo(server, fhandle, info);
return nfs4_map_errors(status);
}
The kernel guys have reported that the new -Wswitch-bool warns on this code
and, while ugly, it was a deliberate decision to write it that way (they make
'creative' use of the fall-through in the switch).
I wonder whether it makes sense to restrict the -Wswitch-bool warning to the
cases where the switch condition becomes a boolean from a complex expression
(i.e. a && 0xff, instead of the probably intended a & 0xff) and not warn when
the switch variable is a simple boolean var.
what do you think?