This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH RFA: More -Wparentheses checks for C++


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]