[Bug libstdc++/23757] iostreams hex formatting for signed integers treats than as unsigned
pcarlini at suse dot de
gcc-bugzilla@gcc.gnu.org
Wed Sep 7 16:28:00 GMT 2005
------- Additional Comments From pcarlini at suse dot de 2005-09-07 16:28 -------
(In reply to comment #7)
> The ANSI definition for %x (or %X) only covers unsigned integers. Surely then
> doing hex formatting on a signed integer would at the very least be undefined
> behavior.
Yes, you have a point that the mapping prescribed by the ISO/IEC Standards is
not very precise, because, strictly speaking, the C Standard speaks only about
unsigned int and the C++ Standard mandates "%x" for many different types (see
22.2.2.2.2/Stage1): then the user is allowed to invoke undefined behavior if
he uses "hex" together with anything != unsigned int, that is, basically,
*always* because unsigned int is not among the types over which do_put is
overloaded! I consider this a defect of the C++ Standard and will take care
of reporting it to the LWG Commitee. Thanks for pointing it out!
As long as libstdc++-v3 is concerned, what we are doing in such circumstances,
is implementing a kind of behavior, which is the one usually implemented
by printf. This is good, in my opinion, because consistent with printf, thus
very useful when C++ and C code interoperate. You are right that in principle
libstdc++-v3 could well crash and remain conforming ;)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23757
More information about the Gcc-bugs
mailing list