This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH RFA: More -Wparentheses checks for C++
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Dec 2006 00:19:09 -0800
- Subject: Re: PATCH RFA: More -Wparentheses checks for C++
- References: <m33b6zverl.fsf@localhost.localdomain>
Ian Lance Taylor wrote:
> Index: gcc/cp/semantics.c
> ===================================================================
> --- gcc/cp/semantics.c (revision 120236)
> +++ gcc/cp/semantics.c (working copy)
> @@ -587,6 +587,16 @@ maybe_convert_cond (tree cond)
>
> /* Do the conversion. */
> cond = convert_from_reference (cond);
> +
> + if (TREE_CODE (cond) == MODIFY_EXPR
> + && !TREE_NO_WARNING (cond)
> + && warn_parentheses)
> + {
> + warning (OPT_Wparentheses,
> + "suggest parentheses around assignment used as truth value");
> + TREE_NO_WARNING (cond) = 1;
> + }
> +
> return condition_conversion (cond);
> }
Will this warn for:
// This is a POD.
struct S {
int i;
};
S s;
if (S(s)) {}
? Because, it would be entirely reasonable for the compiler to turn
that into a MODIFY_EXPR. Right now, it may use INIT_EXPR, but we
vaguely expect INIT_EXPR to go away.
So, I'm afraid that because the C++ front end doesn't have a separate,
later, lowering pass, this might be a dangerous change.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713