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] Implement warning for wrong use of ||/&&


Another nitpick. I think this fixes PR 17946 which already had a
patch. I didn't compare both solutions but it may be worthwhile to
take into account comments in bugzilla and the replies to the original
patch: http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00990.html

(I keep looking for a suitable warning option for this).

Cheers,

Manuel.



On 12/02/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
On 12/02/07, Dirk Mueller <dmueller@suse.de> wrote:
> +
> +         switch (code)
> +           {
> +           case TRUTH_ANDIF_EXPR:
> +           case TRUTH_ORIF_EXPR:
> +            case TRUTH_AND_EXPR:
> +            case TRUTH_OR_EXPR:
> +             if (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
> +                   && !CONSTANT_CLASS_P (arg1)
> +                   && !expl_eq_arg1
> +                   && TREE_CODE (arg2) == INTEGER_CST
> +                   && !integer_zerop (arg2))
> +               {
> +                 warning (OPT_Walways_true, "logical %<%s%> with non-zero constant "
> +                          "will always evaluate as true",
> +                          ((code == TRUTH_ANDIF_EXPR)
> +                           || (code == TRUTH_AND_EXPR)) ? "&&" : "||");
> +                 expl_eq_arg1 = expl_eq_arg2 = true;
> +               }

Just a nitpick. This will print "&&" or "||" even if the code contains
"and" or "or". I think there is already a bug about this somewhere but
I am not sure whether it is a general defect in GCC or something that
must be fixed case by case.

Cheers,

Manuel.



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