Bug 65891 - [12/13/14/15 Regression] -Wlogical-op now warns about logical ‘and’ of equal expressions even when different types/sizeofs are involved
Summary: [12/13/14/15 Regression] -Wlogical-op now warns about logical ‘and’ of equal ...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 11.2.1
: P2 normal
Target Milestone: 12.5
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-04-25 20:18 UTC by Gerald Pfeifer
Modified: 2024-07-19 12:57 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.5.0
Known to fail: 6.1.0
Last reconfirmed: 2015-04-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerald Pfeifer 2015-04-25 20:18:29 UTC
Since 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.

we also diagnose code the following

  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]);
  }

with

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

when these two conditions are about two different types, defined in two
different locations, and the sizes are set differently.
Comment 1 Marek Polacek 2015-04-25 20:22:59 UTC
Sorry.  I'll look into that.
Comment 2 Marek Polacek 2015-04-27 16:09:38 UTC
In the ML I wrote:

I'm afraid there isn't an easy solution to this; the problem is that we fold
sizeof early, so the warning sees

  t < sizeof 4 && t < 4

Thus unassigning for now.
Comment 3 Kai Tietz 2015-04-27 17:26:18 UTC
For C++ delayed folding this issue won't be warned anymore, as for it sizeof isn't folded early.
Comment 4 Jakub Jelinek 2016-04-27 10:58:23 UTC
GCC 6.1 has been released.
Comment 5 Jakub Jelinek 2016-12-21 10:58:51 UTC
GCC 6.3 is being released, adjusting target milestone.
Comment 6 Richard Biener 2017-07-04 08:49:56 UTC
GCC 6.4 is being released, adjusting target milestone.
Comment 7 James Legg 2022-03-23 13:16:15 UTC
(In reply to Kai Tietz from comment #3)
> For C++ delayed folding this issue won't be warned anymore, as for it sizeof
> isn't folded early.

With -fsanitize=integer-divide-by-zero, the spurious warning is still issued in C++.
Comment 8 Richard Biener 2022-05-27 09:35:40 UTC
GCC 9 branch is being closed
Comment 9 Jakub Jelinek 2022-06-28 10:31:31 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 10 Richard Biener 2023-07-07 10:30:46 UTC
GCC 10 branch is being closed.
Comment 11 Richard Biener 2024-07-19 12:57:53 UTC
GCC 11 branch is being closed.