public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/4623: correct uses of _Bool in type-traits.h & instantiations
@ 2001-10-25 22:58 bkoz
0 siblings, 0 replies; 2+ messages in thread
From: bkoz @ 2001-10-25 22:58 UTC (permalink / raw)
To: brendan, gcc-bugs, gcc-patches, gcc-prs, ira, nobody
Synopsis: correct uses of _Bool in type-traits.h & instantiations
State-Changed-From-To: open->closed
State-Changed-By: bkoz
State-Changed-When: Thu Oct 25 22:58:17 2001
State-Changed-Why:
Fixed.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4623&database=gcc
^ permalink raw reply [flat|nested] 2+ messages in thread
* libstdc++/4623: correct uses of _Bool in type-traits.h & instantiations
@ 2001-10-19 14:56 brendan
0 siblings, 0 replies; 2+ messages in thread
From: brendan @ 2001-10-19 14:56 UTC (permalink / raw)
To: gcc-gnats; +Cc: Ira Ruben, gcc-patches
>Number: 4623
>Category: libstdc++
>Synopsis: correct uses of _Bool in type-traits.h & instantiations
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Oct 19 14:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Brendan Kehoe
>Release: CVS tree
>Organization:
>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.
This can become a problem if a source file includes <stdbool.h> and something bringing in type_traits.h. This wasn't a problem when most people used gcc 2.95.x, but now that gcc 3.x is in play, it can cause unexpected headaches.
One workaround in the past has been to add `#undef _Bool' just before the template definition in type_traits.h. But this is not the requisite long-term fix.
I believe there are few if any examples of user code that actually make use of the `_Bool' template type that was made in type_traits.h. However there will be an increasing number of platforms whose system headers may make use of <stdbool.h> in some way, which will produce unexpected compile-time errors for users without a suitable change.
>How-To-Repeat:
A test containing nothing but:
#include <stdbool.h>
#include <string>
will produce an error like
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include/g++/bits/type_traits.h:86:
error: type
specifier `bool' not allowed after struct or class
along with a good number of others afterwards.
>Fix:
The enclosed patch modifies the `_Bool' template to instead be named `__Boolean', and adjusts the two typedefs that use it. In particular, we now have two leading underscores instead of one, to make it obvious that this is a type for an implementation and not something intended for user code.
It also goes into string-inst.cc and misc-inst.cc, and makes them use the two typedefs instead of the underlying template type. That way if any future implementation change is required after this `__Boolean' change, it can be done without requiring spurious source changes.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="diffs-bool.txt"
Content-Disposition: inline; filename="diffs-bool.txt"
2001-10-16 Brendan Kehoe <brendan@zen.org>
* bits/type_traits.h (__Boolean): Renamed template from _Bool.
(__true_type, __false_type): Change usage.
* src/string-inst.cc (__destroy_aux): Change third parm to be
__false_type instead of _Bool<false>.
* src/misc-inst.cc (__uninitialized_fill_n_aux,
__uninitialized_copy_aux): Likewise.
*** include/bits/type_traits.h.~1~ Sun Jul 1 14:56:51 2001
--- include/bits/type_traits.h Tue Oct 16 08:51:05 2001
*************** template <class _Tp> inline void copy(_T
*** 83,90 ****
*/
!
! 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;
template <class _Tp>
*** src/string-inst.cc.~1~ Wed Aug 29 23:22:35 2001
--- src/string-inst.cc Tue Oct 16 08:47:08 2001
*************** namespace std
*** 103,106 ****
template
void
! __destroy_aux<S*>(S*, S*, _Bool<false>);
} // namespace std
--- 103,106 ----
template
void
! __destroy_aux<S*>(S*, S*, __false_type);
} // namespace std
*** src/misc-inst.cc.~1~ Sun Mar 25 15:48:35 2001
--- src/misc-inst.cc Tue Oct 16 08:54:43 2001
*************** namespace std
*** 234,238 ****
string*
__uninitialized_fill_n_aux<string*, size_t, string>
! (string*, size_t, string const &, _Bool<false>);
template
--- 234,238 ----
string*
__uninitialized_fill_n_aux<string*, size_t, string>
! (string*, size_t, string const &, __false_type);
template
*************** namespace std
*** 240,244 ****
__uninitialized_copy_aux<vector<string>::const_iterator, string *>
(vector<string>::const_iterator, vector<string>::const_iterator,
! string*, _Bool<false>);
template
--- 240,244 ----
__uninitialized_copy_aux<vector<string>::const_iterator, string *>
(vector<string>::const_iterator, vector<string>::const_iterator,
! string*, __false_type);
template
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-10-25 22:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-25 22:58 libstdc++/4623: correct uses of _Bool in type-traits.h & instantiations bkoz
-- strict thread matches above, loose matches on Subject: below --
2001-10-19 14:56 brendan
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).