public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32240]  New: wstring::length() does not work properly with --short-wchar
@ 2007-06-07  6:51 jigglypuff at spambob dot com
  2007-06-07  8:51 ` [Bug c++/32240] " pcarlini at suse dot de
  2007-06-07  9:14 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: jigglypuff at spambob dot com @ 2007-06-07  6:51 UTC (permalink / raw)
  To: gcc-bugs

wstring::length() does not work properly with --short-wchar

I'm not sure if this bug is in gcc or glibc. It could be that gcc does not
properly set a certain variable with --short-wchar, or, it could be that glibc
does not properly implement wstring, always assuming a 4-byte wchar_t.

Here is a sample:

// tmp2.cpp
#include <iostream>

int main(int argc, char ** argv)
{
        std::wstring wstr = L"Hello, World!";
        std::wcout << wstr.length() << std::endl;
        return 0;
}

$ g++ -o tmp tmp2.cpp
$ ./tmp
13
$ g++ -o tmp tmp2.cpp --short-wchar
$ ./tmp
19

They should both say 13. ymmv, but the length value given is usually wrong. How
wrong may vary.


-- 
           Summary: wstring::length() does not work properly with --short-
                    wchar
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jigglypuff at spambob dot com
 GCC build triplet: ?
  GCC host triplet: i686-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32240


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/32240] wstring::length() does not work properly with --short-wchar
  2007-06-07  6:51 [Bug c++/32240] New: wstring::length() does not work properly with --short-wchar jigglypuff at spambob dot com
@ 2007-06-07  8:51 ` pcarlini at suse dot de
  2007-06-07  9:14 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pcarlini at suse dot de @ 2007-06-07  8:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pcarlini at suse dot de  2007-06-07 08:51 -------
(In reply to comment #0)
>         std::wstring wstr = L"Hello, World!";

A couple of clarifications. First, your way of using --short-wchar cannot work
in principle, because std::string functions are exported from the installed
.so, which is built *without* --short-wchar. At minimum, for consistency, the
library itself should be rebuilt at installation time with that switch. In the
specific case above, where you are using the constructor taking a "C" string,
it forwards to the underlying glibc wcslen in order to compute the length of
the initializer "C" string, which is computing the length incorrectly: we
alredy knew that, glibc doesn't work completely fine together with
--short-wchar: the docs are pretty clear that on GNU systems a wchar_t is
always assumed to be 32 bits. I don't think there is a way to deal portably
with such issues within C++03: the new C++0x will include char16_t and char23_t
types and everything will be straightforward. In the meanwhile, as far as I
know, most of the library has chances to work fine if you provide replacement
std::char_traits not forwarding to underlying C functions.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32240


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/32240] wstring::length() does not work properly with --short-wchar
  2007-06-07  6:51 [Bug c++/32240] New: wstring::length() does not work properly with --short-wchar jigglypuff at spambob dot com
  2007-06-07  8:51 ` [Bug c++/32240] " pcarlini at suse dot de
@ 2007-06-07  9:14 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-07  9:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-06-07 09:14 -------
This is neither a GCC bug or a glibc bug as -fshort-wchar changes the ABI.
The documentation already mentions this:
Warning: the -fshort-wchar switch causes GCC to generate code that is not
binary compatible with code generated without that switch. Use it to conform to
a non-default application binary interface. 


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32240


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-07  9:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-07  6:51 [Bug c++/32240] New: wstring::length() does not work properly with --short-wchar jigglypuff at spambob dot com
2007-06-07  8:51 ` [Bug c++/32240] " pcarlini at suse dot de
2007-06-07  9:14 ` pinskia at gcc dot gnu dot org

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).