Bug 34455 - Request warning for casts to _Bool
Summary: Request warning for casts to _Bool
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-13 19:50 UTC by H. Peter Anvin
Modified: 2017-07-27 11:35 UTC (History)
2 users (show)

See Also:
Host: all
Target: all
Build: all
Known to work:
Known to fail:
Last reconfirmed: 2012-04-18 00:00:00


Attachments
Proposed test cases (245 bytes, text/plain)
2007-12-13 19:56 UTC, H. Peter Anvin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H. Peter Anvin 2007-12-13 19:50:44 UTC
I recently finished converting a large codebase from using "int" to using "bool" (i.e. _Bool) for booleans.  This is a big win for debuggability.  However, unfortunately the code has to be portable to inferior compilers which don't have _Bool implemented yet; for those we use:

typedef enum { false, true } bool;

As such, it would be a very nice thing to have an optional warning for any conversions of non-boolean objects (those not known to contain only 0 or 1) to _Bool using either an implicit conversion or a cast.  The "safe" way to do it in a backwards-compatible way is using the !! pseudo-operator.
Comment 1 H. Peter Anvin 2007-12-13 19:56:30 UTC
Created attachment 14746 [details]
Proposed test cases
Comment 2 H. Peter Anvin 2009-02-26 22:56:16 UTC
Any interest in this at all?  This is a major missing feature for me at the moment.
Comment 3 Manuel López-Ibáñez 2012-04-18 16:42:46 UTC
To be honest, I am not sure whether this is really useful or not for other people. And I am not sure whether it is actually possible.

What I am sure is that there is nobody except you interested in implementing it, so if you want to get it done, you will have to work on it (or pay someone to do it).

Meanwhile, I am putting this in WAITING, so it doesn't show up as pending confirmation.
Comment 4 Eric Gallager 2017-07-27 01:09:15 UTC
(In reply to Manuel López-Ibáñez from comment #3)
> To be honest, I am not sure whether this is really useful or not for other
> people. And I am not sure whether it is actually possible.
> 
> What I am sure is that there is nobody except you interested in implementing
> it, so if you want to get it done, you will have to work on it (or pay
> someone to do it).
> 
> Meanwhile, I am putting this in WAITING, so it doesn't show up as pending
> confirmation.

Changing to SUSPENDED so people don't close it from being in WAITING for so long
Comment 5 H. Peter Anvin 2017-07-27 10:33:23 UTC
10 years have passed since the original request.  These days compilers that don't have any support for bool at all can be genuinely considered rare at the very best.  I don't think it is applicable anymore.
Comment 6 Marek Polacek 2017-07-27 11:35:05 UTC
Thanks, closing out then.