On 07/22/2015 02:02 PM, Marek Polacek wrote:
On Wed, Jul 22, 2015 at 01:48:03PM -0600, Martin Sebor wrote:
On 07/22/2015 01:06 PM, Marek Polacek wrote:
On Wed, Jul 22, 2015 at 12:43:53PM -0600, Martin Sebor wrote:
On 07/14/2015 09:18 AM, Marek Polacek wrote:
Code such as "if (i == i)" is hardly ever desirable, so we should be able
to warn about this to prevent dumb mistakes.

I haven't tried the patch or even studied it very carefully but
I wonder if this is also the case when i is declared volatile.
I.e., do we want to issue a warning there? (If we do, the text
of the warning would need to be adjusted in those cases since
the expression need not evaluate to true.)

We don't warn for volatiles because operand_equal_p doesn't consider
decls with side effects as same.  Admittedly the test doesn't test
that...

I see. Thanks for clarifying that. Not warning makes sense. I would
suggest to add a test case for it then to make sure it's deliberate.

Here:

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-07-22  Marek Polacek  <pola...@redhat.com>

        PR c++/66555
        PR c/54979
        * c-common.c (find_array_ref_with_const_idx_r): New function.
        (warn_tautological_cmp): New function.
        * c-common.h (warn_tautological_cmp): Declare.
        * c.opt (Wtautological-compare): New option.

        * c-typeck.c (parser_build_binary_op): Call warn_tautological_cmp.

        * call.c (build_new_op_1): Call warn_tautological_cmp.
        * pt.c (tsubst_copy_and_build): Use sentinel to suppress tautological
        compare warnings.

        * doc/invoke.texi: Document -Wtautological-compare.

        * c-c++-common/Wtautological-compare-1.c: New test.
OK. Note I think the pt.c change will need trivial updating as it conflicts with another change of yours that I approved recently.

jeff

Reply via email to