public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Request for warnings on implicit bool to int conversions
@ 2012-03-27 22:43 mathog
  2012-03-28  1:00 ` Paolo Carlini
  2012-03-28  9:00 ` Franz Sirl
  0 siblings, 2 replies; 15+ messages in thread
From: mathog @ 2012-03-27 22:43 UTC (permalink / raw)
  To: gcc

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 integer, but it acts like a bool.  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.

This issued was recently discussed in newsgroup comp.lang.c under the 
subject:
  c99 and the lack of warnings when int operations are applied to a bool

Thank you,

David Mathog
mathog@caltech.edu
Manager, Sequence Analysis Facility, Biology Division, Caltech

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

end of thread, other threads:[~2012-03-29 17:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-27 22:43 Request for warnings on implicit bool to int conversions mathog
2012-03-28  1:00 ` Paolo Carlini
2012-03-28  1:19   ` Gabriel Dos Reis
2012-03-28  2:21     ` Russ Allbery
2012-03-28  2:30       ` Gabriel Dos Reis
2012-03-28  2:40         ` Russ Allbery
2012-03-28  2:48           ` Russ Allbery
2012-03-28 19:32       ` [bool wrapping] " Michael Witten
2012-03-28 20:30         ` mathog
2012-03-28 22:21           ` Michael Witten
2012-03-28 22:52             ` mathog
2012-03-29 10:29               ` David Brown
2012-03-29 17:49                 ` mathog
2012-03-28 22:28           ` Michael Witten
2012-03-28  9:00 ` Franz Sirl

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).