This is the mail archive of the
mailing list for the GCC project.
Re: [C PATCH] Warn if switch has boolean value (PR c/60439)
- From: Jeff Law <law at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>, Steven Bosscher <stevenb dot gcc at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Thu, 01 May 2014 23:09:04 -0600
- Subject: Re: [C PATCH] Warn if switch has boolean value (PR c/60439)
- Authentication-results: sourceware.org; auth=none
- References: <20140418053021 dot GH20332 at redhat dot com> <CABu31nO7XjjEJCZCf_vLFgfpvuejdxcmeF6YB4++8sAGkHjJ8A at mail dot gmail dot com> <20140418115013 dot GK20332 at redhat dot com>
On 04/18/14 05:50, Marek Polacek wrote:
Looks reasonable, though I do wonder if we should be warning for this in
the C++ front-end as well?
On Fri, Apr 18, 2014 at 01:20:59PM +0200, Steven Bosscher wrote:
On Fri, Apr 18, 2014 at 7:30 AM, Marek Polacek wrote:
+ if (TREE_CODE (type) == BOOLEAN_TYPE
+ || exp_code == TRUTH_ANDIF_EXPR
+ || exp_code == TRUTH_AND_EXPR
+ || exp_code == TRUTH_ORIF_EXPR
+ || exp_code == TRUTH_OR_EXPR
+ || exp_code == TRUTH_XOR_EXPR
+ || exp_code == TRUTH_NOT_EXPR
+ || exp_code == EQ_EXPR
+ || exp_code == NE_EXPR
+ || exp_code == LE_EXPR
+ || exp_code == GE_EXPR
+ || exp_code == LT_EXPR
+ || exp_code == GT_EXPR)
Is there a TREE_CODE_CLASS or a #define for this?
Good question. I was looking for something nicer and found nothing,
no T_C_C or #define.
But now when I'm looking again, I found truth_value_p... Thanks.
2014-04-18 Marek Polacek <email@example.com>
* doc/invoke.texi: Document -Wswitch-bool.
* c-typeck.c (c_start_case): Warn if switch condition has boolean
* c.opt (Wswitch-bool): New option.
* gcc.dg/pr60439.c: New test.