mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Compiler warning about comparing result of !!test_bit() to an integer
@ 2015-04-27 14:13 David Howells
  2015-04-27 14:25 ` Jiri Kosina
  2015-04-27 15:17 ` David Howells
  0 siblings, 2 replies; 3+ messages in thread
From: David Howells @ 2015-04-27 14:13 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: dhowells, linux-kernel

Hi Jiri,

This line in hid-input.c:

	if (usage->type == EV_KEY && !!test_bit(usage->code, input->key) != value)
		input_event(input, EV_MSC, MSC_SCAN, usage->hid);

gives:

../drivers/hid/hid-input.c: In function 'hidinput_hid_event':
../drivers/hid/hid-input.c:1160:167: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]

with gcc-5.1.  Given that 'value' doesn't appear to be a boolean, is this correct?

This was introduced by commit c01d50d181f074a60bf3ed54eb055ce1679afb98.

David

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiler warning about comparing result of !!test_bit() to an integer
  2015-04-27 14:13 Compiler warning about comparing result of !!test_bit() to an integer David Howells
@ 2015-04-27 14:25 ` Jiri Kosina
  2015-04-27 15:17 ` David Howells
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2015-04-27 14:25 UTC (permalink / raw)
  To: David Howells; +Cc: linux-kernel

On Mon, 27 Apr 2015, David Howells wrote:

> Hi Jiri,
> 
> This line in hid-input.c:
> 
> 	if (usage->type == EV_KEY && !!test_bit(usage->code, input->key) != value)
> 		input_event(input, EV_MSC, MSC_SCAN, usage->hid);
> 
> gives:
> 
> ../drivers/hid/hid-input.c: In function 'hidinput_hid_event':
> ../drivers/hid/hid-input.c:1160:167: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
> 
> with gcc-5.1.  Given that 'value' doesn't appear to be a boolean, is this correct?

gcc-5 became somehow very picky about '!!' usages. I recall quite some 
internal discussions with our gcc guys, which resulted in upstream gcc 
bugzillas being filled about gcc warning in completely legitimate cases.

> 
> This was introduced by commit c01d50d181f074a60bf3ed54eb055ce1679afb98.

Gah, that was long time ago! :)

This is because we want to handle autorepeat (i.e. value 2) correctly. Now 
that you ask, it seems to me that we actually should be doing

	!!test_bit(usage->code, input->key) != !!value

to be really exact (i.e. so that we really can't have oscilating state).

I'll think about it a little bit more, and eventually probably fix it this 
way with your Reported-by: if you are OK with that.

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Compiler warning about comparing result of !!test_bit() to an integer
  2015-04-27 14:13 Compiler warning about comparing result of !!test_bit() to an integer David Howells
  2015-04-27 14:25 ` Jiri Kosina
@ 2015-04-27 15:17 ` David Howells
  1 sibling, 0 replies; 3+ messages in thread
From: David Howells @ 2015-04-27 15:17 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: dhowells, linux-kernel

Jiri Kosina <jkosina@suse.cz> wrote:

> gcc-5 became somehow very picky about '!!' usages. I recall quite some 
> internal discussions with our gcc guys, which resulted in upstream gcc 
> bugzillas being filled about gcc warning in completely legitimate cases.

I suspect it's more that it's picky about '!' usages - which covers '!!'.  I'm
guessing they're trying to pick up people doing if(!x==y) when they mean
if(!(x==y)) or somesuch.
Jiri Kosina <jkosina@suse.cz> wrote:

> This is because we want to handle autorepeat (i.e. value 2) correctly. Now 
> that you ask, it seems to me that we actually should be doing
> 
> 	!!test_bit(usage->code, input->key) != !!value

I wonder if you could cast to bool instead?  test_bit() possibly *should*
return a bool these days, thus rendering the '!!' unnecessary.

> to be really exact (i.e. so that we really can't have oscilating state).
> 
> I'll think about it a little bit more, and eventually probably fix it this 
> way with your Reported-by: if you are OK with that.

Yep.

David

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-27 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-27 14:13 Compiler warning about comparing result of !!test_bit() to an integer David Howells
2015-04-27 14:25 ` Jiri Kosina
2015-04-27 15:17 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®