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] Warn for dangerous use of omitted middle operand in ?: v4


Andi Kleen <andi@firstfloor.org> writes:

> 2009-01-18  Andi Kleen  <ak@linux.intel.com>
>
>         * gcc.dg/warn-omitted-condop.c: Add
>         * g++.dg/warn-omitted-condop.C: Add
>         * cp/parser.c: (cp_parser_question_colon_clause): 
> 	Switch to use cp_lexer_peek_token.
>         Call warn_for_omitted_condop. Call pedwarn for omitted
> 	middle operand.
>         * c-parser.c: (c_parser_conditional_expression) 
>         Call warn_for_omitted_condop.
>         * c-common.c (warn_for_omitted_condop): Add.
>         * c-common.h (warn_for_omitted_condop): Add prototype.
> 	* doc/invoke.texi: Document omitted condop warning.

This is OK for gcc 4.5 (not for mainline--it's a new feature), with
the following changes.

> +  if (TREE_CODE_CLASS (code) == tcc_comparison ||
> +      code == TRUTH_ANDIF_EXPR || 
> +      code == TRUTH_ORIF_EXPR || 
> +      code == TRUTH_ANDIF_EXPR || 
> +      code == TRUTH_NOT_EXPR)

Put || at the start of the line, not at the end of the line.  Check
for TRUTH_AND_EXPR rather than checking for TRUTH_ANDIF_EXPR twice.
Check for TRUTH_OR_EXPR and TRUTH_XOR_EXPR.

Thanks.

Ian


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