public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gerald Pfeifer <gerald@pfeifer.com>
To: Marek Polacek <polacek@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [C/C++ PATCH] Improve -Wlogical-op (PR c/63357)
Date: Sat, 25 Apr 2015 20:19:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1504252146530.3191@tuna.site> (raw)

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]


> 2015-04-21  Marek Polacek  <polacek@redhat.com>
>
>	PR c/63357
>	* c-common.c (warn_logical_operator): Warn if the operands have the
>	same expressions.

This is nice!  It really helped me find an issue or two in the 
Wine project.

Unfortunately it also causes false positives:

  int report (unsigned t)
  {
    typedef int r_fun_t (int);

    static r_fun_t * text_funcs[7];
    static r_fun_t * GUI_funcs[7];

    return (t < sizeof text_funcs / sizeof text_funcs[0] &&
            t < sizeof GUI_funcs / sizeof GUI_funcs[0]);
  }

Where we now warn as follows:

  input: In function Β‘reportΒ’:
  input:8:58: warning: logical Β‘andΒ’ of equal expressions [-Wlogical-op]
     return (t < sizeof text_funcs / sizeof text_funcs[0] &&
                                                          ^

In case this example feels too contrived (even though it is an
excerpt of Wine code), we now also warn about the following where
the two types and variables are defined in different places and
the size of one is set implicitly:

  typedef int r_fun_t (int);

  r_fun_t * text_funcs[] = {0,0,0};

  int report (unsigned t)
  {
    typedef int s_fun_t (long, char);

    static s_fun_t * GUI_funcs[3];

    return (t < sizeof text_funcs / sizeof text_funcs[0] &&
            t < sizeof GUI_funcs / sizeof GUI_funcs[0]);
  }

(I also filed this as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65891
so that we keep track.)

Gerald

             reply	other threads:[~2015-04-25 20:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-25 20:19 Gerald Pfeifer [this message]
2015-04-27 14:47 ` Marek Polacek
2015-04-27 14:50   ` Marek Polacek
2015-04-27 16:06   ` Jeff Law
2015-04-27 16:10     ` Marek Polacek
  -- strict thread matches above, loose matches on Subject: below --
2015-04-21 11:16 Marek Polacek
2015-04-21 14:19 ` Manuel López-Ibáñez
2015-04-22  8:59   ` Marek Polacek
2015-04-22  9:51     ` Manuel López-Ibáñez
2015-04-22  9:54       ` Manuel López-Ibáñez
2015-04-22 11:12       ` Marek Polacek
2015-04-23 22:02 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.1504252146530.3191@tuna.site \
    --to=gerald@pfeifer.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).