correct uses of _Bool in type-traits.h & instantiations

Gabriel Dos Reis gdr@codesourcery.com
Fri Oct 19 17:37:00 GMT 2001


brendan@zen.org writes:

| >Category:       libstdc++
| >Synopsis:       correct uses of _Bool in type-traits.h & instantiations
| >Confidential:   no
| >Severity:       serious
| >Priority:       high
| >Class:          sw-bug
| >Submitter-Id:   net
| >Originator:     Brendan Kehoe
| >Release:        CVS tree
| >Environment:
| 
| >Description:
| In type-traits.h, it creates an internal template named `_Bool', in order to make two typedefs `__true_type' and `__false_type'.  While the ISO C++ standard doesn't make any mention of `_Bool', the ISO C99 C standard does reserve `_Bool' in $6.7.2.

Hi Brendan,

  A partial patch for exactly this problem  was posted to libstdc++
three of four days ago.  Actually, the _Bool thingy can just go away,
as it is not needed.

[...]

| ! template <bool _Truth> struct _Bool {};
| ! typedef _Bool<true>  __true_type;
| ! typedef _Bool<false> __false_type;
|   
|   template <class _Tp>
| --- 83,93 ----
|   */
|   
| ! // Note that we must use an internal name of __Boolean here, since the
| ! // identifier of _Bool, as we'd used in the past, is in fact reserved
| ! // by the C99 standard ($6.7.2).  As such, we'd introduce headaches if
| ! // someone happens to include <stdbool.h> along with this file.
| ! template <bool _Truth> struct __Boolean {};
| ! typedef __Boolean<true>  __true_type;
| ! typedef __Boolean<false> __false_type;

_Bool should go away so that the above reads

	struct __true_type { };
	struct __false_type { };

The rest is OK.

Thanks,

-- Gaby
CodeSourcery, LLC                       http://www.codesourcery.com



More information about the Gcc-patches mailing list