Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-29 Thread mathog
On 29-Mar-2012 03:20, David Brown wrote: On 29/03/2012 00:52, mathog wrote: A better solution for the aesthetics would have been (it is a bit late now) to implement the missing unary negation operator: !!b; //T->F, F->T You can't do that, because "!!" is already a useful operator on integ

Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-29 Thread David Brown
On 29/03/2012 00:52, mathog wrote: On 28-Mar-2012 15:20, Michael Witten wrote: However, it seems to me that toggling the value with the idiom: --b; is aesthetically preferable to the more elaborate: b = !b; Aesthetically, not logically. Neither of these makes the least bit of sense: one l

Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-28 Thread mathog
On 28-Mar-2012 15:20, Michael Witten wrote: However, it seems to me that toggling the value with the idiom: --b; is aesthetically preferable to the more elaborate: b = !b; Aesthetically, not logically. Neither of these makes the least bit of sense: one less than False one less

Re: Request for warnings on implicit bool to int conversions

2012-03-28 Thread Michael Witten
On Wed, Mar 28, 2012 at 20:30, David Mathog wrote: > ... > >> gcc -std=c99 -pedantic -Wall -O0 -fdump-tree-gimple d.c > > > That's a trick worth knowing. Thanks! > Ran that on a test program and in every case but one there was an implicit > > (int) b > > on sections of code which I though shoul

Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-28 Thread Michael Witten
On Wed, Mar 28, 2012 at 20:30, mathog wrote: > Since b-- is equivalent to [assigning] !b, > and b++ is equivalent to [assigning] 1, if > that action is intended, there is no reason > to use either the increment or decrement > operators on a bool. However, it seems to me that toggling the value w

Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-28 Thread mathog
On 28-Mar-2012 12:18, Michael Witten wrote: Wow, that was thorough! The behavior of b++ vs. b-- was interesting, but is yet one more reason why the warning is needed. Since b-- is equivalent to !b, and b++ is equivalent to 1, if that action is intended, there is no reason to use either the i

Re: [bool wrapping] Request for warnings on implicit bool to int conversions

2012-03-28 Thread Michael Witten
On Tue, 27 Mar 2012 19:20:52 -0700, Russ Allbery wrote: > (For example, b++ could easily wrap, and unexpectedly fast > depending on the size of bool on a platform.) Actually, it would appear that a bool (or a _Bool) can't wrap on increment, but it CAN wrap on decrement (and strangely, when the op

Re: Request for warnings on implicit bool to int conversions

2012-03-28 Thread Franz Sirl
Am 2012-03-28 00:43, schrieb mathog: The C99 bool data type, and the similar type in C++, currently (v 4.5.2) do not generate warnings for any of these sorts of operations: bool b; b = 3; b++; b += 2; if(b == 3) The last one is PR 44077. Franz

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Russ Allbery
Russ Allbery writes: > Yeah. But I suspect it was a mistaken statement. The subject line from > the referenced comp.lang.c thread was: > c99 and the lack of warnings when int operations are applied to a bool > which I think is best caught by the conversion *to* bool when the result > is s

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Russ Allbery
Gabriel Dos Reis writes: > I can easily see why an implicit conversion from int to bool might cause > a problem, even if that is what the language standard mandates -- just > look at the most common misuses of strcmp. But, that is not what the > proposer requested, which got me scratching my hea

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Gabriel Dos Reis
On Tue, Mar 27, 2012 at 9:20 PM, Russ Allbery wrote: > Gabriel Dos Reis writes: > >> I am trying to understand what the real issue is here.  Do you want >> -Wimplicit-char-to-int to?  -Wimplicit-short-to-int?  If not, why? >> where to stop? > > I think it's more about conversion *to* bool than fr

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Russ Allbery
Gabriel Dos Reis writes: > I am trying to understand what the real issue is here. Do you want > -Wimplicit-char-to-int to? -Wimplicit-short-to-int? If not, why? > where to stop? I think it's more about conversion *to* bool than from bool, and it catches places where code has been partly conve

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Gabriel Dos Reis
> Hi, >> >> It would be nice if there was a >> >>  -Wimplicit_bool >> >> that was enabled in -Wall which complained about these sorts of >> operations.  In particular >> it would warn any time a bool was implicitly promoted to an int. > I am trying to understand what the real issue is here. Do yo

Re: Request for warnings on implicit bool to int conversions

2012-03-27 Thread Paolo Carlini
Hi, It would be nice if there was a -Wimplicit_bool that was enabled in -Wall which complained about these sorts of operations. In particular it would warn any time a bool was implicitly promoted to an int. first blush your message should be a Bugzilla PR, this way the request doesn't ris

Request for warnings on implicit bool to int conversions

2012-03-27 Thread mathog
The C99 bool data type, and the similar type in C++, currently (v 4.5.2) do not generate warnings for any of these sorts of operations: bool b; b = 3; b++; b += 2; if(b == 3) etc. This can lead to a lot of hidden mischief because a variable declared far away may look like an intege