This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Handle enum bit-fields for -Wswitch (PR c/61405, PR c/53874)
- From: Jason Merrill <jason at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>, Jakub Jelinek <jakub at redhat dot com>, Jan Hubicka <hubicka at ucw dot cz>
- Date: Fri, 19 Sep 2014 15:39:39 -0400
- Subject: Re: [C/C++ PATCH] Handle enum bit-fields for -Wswitch (PR c/61405, PR c/53874)
- Authentication-results: sourceware.org; auth=none
- References: <20140919132944 dot GA743 at redhat dot com>
On 09/19/2014 09:29 AM, Marek Polacek wrote:
But we also started to warn on
CPP_KEYWORD and two others: "case value not in enumerated type".
Fixed by moving CPP_KEYWORD, CPP_TEMPLATE_ID, and CPP_NESTED_NAME_SPECIFIER
into enum cpp_ttype. Not sure if this is going to hurt something else.
Wait, -Wswitch warns if any of the case labels don't correspond to
enumerators? Apparently so, it complains about
enum E { a=1,b=2,c=4 } e;
int main()
{
switch (e)
{
case a|b: break;
default: break;
}
}
That seems bogus. The docs say,
"'case' labels outside the enumeration range also provoke warnings when
this option is used (even if there is a 'default' label)."
but 3 is within the range 1-4.
If this is working as intended, I'm still uneasy about moving the C++
internal token types into libcpp; instead, I think I'd prefer to work
around the warning by suppressing -Wswitch inside affected functions or
moving the cases to ifs.
Jason