On Mon, Apr 27, 2015 at 04:47:12PM +0200, Marek Polacek wrote: > On Sat, Apr 25, 2015 at 10:18:59PM +0200, Gerald Pfeifer wrote: > > 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.) > > 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 > > and warns. Maybe using SIZEOF_EXPR would help...
That said, this isn't something that regressed with my patch. Consider e.g.: struct S { int i; }; struct T { int i; }; int foo (unsigned int t) { return t < sizeof (struct S) && t > sizeof (struct T); } with -Wlogical-op: w2.c: In function ‘foo’: w2.c:6:32: warning: logical ‘and’ of mutually exclusive tests is always false [-Wlogical-op] return t < sizeof (struct S) && t > sizeof (struct T); ^