Bug 22936

Summary: /usr/include/stdbool.h defines _bool twice when included by gcc.
Product: Base System Reporter: Donald.J.Maddox <Donald.J.Maddox>
Component: miscAssignee: Jeroen Ruigrok van der Werven <asmodai>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Donald.J.Maddox 2000-11-18 09:00:00 UTC
	The header file <stdbool.h> contains a defective
conditional that breaks several ports.  Any code that includes
<stdbool.h> will break if compiled by gcc...  Example:

#include <stdbool.h>

int main()
{
	return(0);
}

$ cc test.c
In file included from test.c:1:
/usr/include/stdbool.h:51: conflicting types for `_Bool'
/usr/include/stdbool.h:38: previous declaration of `_Bool'

How-To-Repeat: 	See above :)
Comment 1 Bruce Evans 2000-11-18 17:18:45 UTC
On Sat, 18 Nov 2000 Donald.J.Maddox@cae88-102-101.sc.rr.com wrote:

> >Description:
> 	The header file <stdbool.h> contains a defective
> conditional that breaks several ports.  Any code that includes
> <stdbool.h> will break if compiled by gcc...  Example:

Much more is broken than that, at least according to a C99 draft (n869).
1) _Bool is a first class type (like int), so it can't be declared as
   a typedef (unless compiler magic supports such a declaration).
2) `true' and `false' are supposed to be usable in cpp expressions, so
   they can't be declared as enum values.
3) The definitions of `false' and `true' as themself don't work in K&R
   mode.  This is not a serious bug, since K&R code shouldn't include
   <stdbool.h>.
4) Support for the Standard C (c99) _Bool is premature, since gcc doesn't
   support _Bool as a first class type.

<stdbool.h> is essentially a compatibility hack for pre-c99 compilers.
The current version seems to be based on the gcc version.  Both versions
will break when gcc actually supports _Bool.

Here is a version compatible with the C99 draft and K&R:

---
#define	__bool_true_false_are_defined	1
#define	false	0
#define	true	1

#define	bool	_Bool
#if __STDC_VERSION__ < 199901L
typedef	int	_Bool;
#endif
---

Bruce
Comment 2 Donald J. Maddox 2000-11-18 18:39:09 UTC
Thanks.  Are you going to commit your fix and close the PR?

On Sun, Nov 19, 2000 at 04:18:45AM +1100, Bruce Evans wrote:
> On Sat, 18 Nov 2000 Donald.J.Maddox@cae88-102-101.sc.rr.com wrote:
> 
> > >Description:
> > 	The header file <stdbool.h> contains a defective
> > conditional that breaks several ports.  Any code that includes
> > <stdbool.h> will break if compiled by gcc...  Example:
> 
> Much more is broken than that, at least according to a C99 draft (n869).
> 1) _Bool is a first class type (like int), so it can't be declared as
>    a typedef (unless compiler magic supports such a declaration).
> 2) `true' and `false' are supposed to be usable in cpp expressions, so
>    they can't be declared as enum values.
> 3) The definitions of `false' and `true' as themself don't work in K&R
>    mode.  This is not a serious bug, since K&R code shouldn't include
>    <stdbool.h>.
> 4) Support for the Standard C (c99) _Bool is premature, since gcc doesn't
>    support _Bool as a first class type.
> 
> <stdbool.h> is essentially a compatibility hack for pre-c99 compilers.
> The current version seems to be based on the gcc version.  Both versions
> will break when gcc actually supports _Bool.
> 
> Here is a version compatible with the C99 draft and K&R:
> 
> ---
> #define	__bool_true_false_are_defined	1
> #define	false	0
> #define	true	1
> 
> #define	bool	_Bool
> #if __STDC_VERSION__ < 199901L
> typedef	int	_Bool;
> #endif
> ---
> 
> Bruce
>
Comment 3 Bruce Evans 2000-11-18 22:32:01 UTC
On Sat, 18 Nov 2000, Donald J . Maddox wrote:

> Thanks.  Are you going to commit your fix and close the PR?

I hope the committer of <stdbool.h> wll fix it.  I didn't get around
to reviewing it before it was committed :(.

Bruce
Comment 4 Maxim Sobolev freebsd_committer freebsd_triage 2000-11-21 17:35:32 UTC
Responsible Changed
From-To: freebsd-bugs->asmodai

Asmo brought it, so he'll fix it.
Comment 5 Jeroen Ruigrok van der Werven freebsd_committer freebsd_triage 2000-11-29 14:41:18 UTC
State Changed
From-To: open->suspended

Committed a fix per bde's suggestions. 

Put on suspend until sobomax is happy.
Comment 6 Donald J. Maddox 2001-01-01 22:44:12 UTC
This PR is suspended 'until sobomax is happy'...

Is he happy yet? :)
Comment 7 Maxim Sobolev freebsd_committer freebsd_triage 2001-01-01 23:15:56 UTC
State Changed
From-To: suspended->closed

I'm happy now, whatever it means!!!