[Bug libstdc++/12062] New: wide chars problems

jm at bourguet dot org gcc-bugzilla@gcc.gnu.org
Tue Aug 26 10:11:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: wide chars problems
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jm at bourguet dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

$ cat wcout.cpp
#include <iostream>
#include <fstream>
#include <locale>
#include <wchar.h>

int main() {
  std::locale::global(std::locale(""));
  try {
    std::wcout.imbue(std::locale());
  } catch (std::exception& e) {
    std::cerr << "std::exception on imbue() " << e.what() << std::endl;
  } catch (...) {
    std::cerr << "unknown exception on imbue()" << std::endl;
  }
  if (!std::wcout) {
    std::cerr << "imbue failed on wcout" << std::endl;
    std::wcout.clear();
  }
  std::cerr << "wcout locale: " << std::wcout.rdbuf()->getloc().name()
            << std::endl;

  std::cerr << "Trying to output to wcout" << std::endl;
  std::wcout << L"\u0153\u00EE" << std::endl;
  if (!std::wcout) {
    std::wcout.clear();
    std::wcout << std::endl;
    std::cerr << "\nwcout failed\n" << std::endl;
  }

  std::cerr << "Trying to output to file" << std::endl;
  std::wofstream os("file");
  os.imbue(std::locale());
  os << L"\u0153\u00EE" << std::endl;
  if (!os) {
    std::cerr << "\noutput to file failed\n" << std::endl;
    os.clear();
    os << std::endl;
  }
}
$ g++-3.3 -W -Wall -pedantic-errors -std=c++98 -o wcout wcout.cpp
$ LANG=C ./wcout | od -t x1
wcout locale: C
Trying to output to wcout

wcout failed

Trying to output to file

output to file failed

0000000 0a
0000001
$ od -t x1 file 
0000000
$

Why file do not contains a 0a character?

$ LANG=fr_FR ./wcout | od -t x1
wcout locale: fr_FR
Trying to output to wcout

wcout failed

Trying to output to file

output to file failed

0000000 0a
0000001
$ od -t x1 file 
0000000

Same problem.

$ LANG=fr_FR@euro ./wcout | od -t x1
wcout locale: fr_FR@euro
Trying to output to wcout
Trying to output to file
0000000 bd ee 0a
0000003
$ od -t x1 file 
0000000 bd ee 0a
0000003

This is the expected output.

$ LANG=fr_FR.utf8 ./wcout | od -t x1
wcout locale: fr_FR.utf8
Trying to output to wcout

wcout failed

Trying to output to file
0000000 0a
0000001
$ od -t x1 file 
0000000 c5 93 c3 ae
0000004

Why does this fail on wcout but seem to succeed when writing to a file.
Why doesn't the file contain a 0a character?

Yours,



More information about the Gcc-bugs mailing list