Bug 18672

Summary: std::basic_string<unsigned char>::c_str() doesn't compile
Product: Base System Reporter: ganssauge <ganssauge>
Component: gnuAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description ganssauge 2000-05-19 08:10:01 UTC
std::basic_string<unsigned char>::c_str() doesn't compile

Fix: Use the following patch:
How-To-Repeat: Consider the following Shell-script:
#!/bin/sh
cat >x.cc <<__EOF__
# include <string>

typedef unsigned char BYTE;
typedef basic_string<BYTE> bstring;

const BYTE *get_cstr(bstring const &s) { return (s.c_str()); }
__EOF__

set -x
cat x.cc
c++ -c x.cc

if you run that script, you get the following output:
+ cat x.cc
# include <string>

typedef unsigned char BYTE;
typedef basic_string<BYTE> bstring;

const BYTE *get_cstr(bstring const &s) { return (s.c_str()); }
+ c++ -c x.cc
/usr/include/g++/std/bastring.h: In method `const BYTE * basic_string<unsigned char,string_char_traits<unsigned char>,__default_alloc_template<false,0> >::c_str() const':
x.cc:6:   instantiated from here
/usr/include/g++/std/bastring.h:338: return to `const BYTE *' from `const char *' changes signedness
Comment 1 Jens Schweikhardt freebsd_committer freebsd_triage 2001-06-17 12:44:07 UTC
State Changed
From-To: open->feedback

I can't reproduce this. Instead the script produces this on -current: 

schweikh@hal9000:~/tmp $ ./tst 
+ cat x.cc 
# include <string> 

typedef unsigned char BYTE; 
typedef basic_string<BYTE> bstring; 

const BYTE *get_cstbstring const &s) { returns.c_st)); } 
+ c++ -c x.cc 
x.cc:6: syntax error before `const'
Comment 2 Jens Schweikhardt freebsd_committer freebsd_triage 2001-06-17 12:54:39 UTC
State Changed
From-To: feedback->open

Whoops; pasto. I can reproduce it. Have you submitted this to the 
GNU folks?
Comment 3 ganssauge 2001-06-17 22:26:12 UTC
No I didn't.
It was already being addressed in the new libstdc++-Project.
The latest gcc-3.0 snapshot does not have a problem with that code (if you
add "using namespace std;" at the proper place).
My motivation at that time (it's only 13 months since then) was a fix within
the frame of the FreeBSD project, because that
was my primary development platform at that time and I'm still doing cvsup
and build/install world on a regular basis.
Don't get me wrong, I personally don't mind to install a patched version of
that header myself on my own machine,
but I absolutely hate it when I need to reinstall that patch every so often.
So if it's not an option to make that fix within the FreeBSD copy of the
GNU-Sources, please close the PR.

Cheers,

Gottfried
Comment 4 Mike Barcroft freebsd_committer freebsd_triage 2001-07-22 03:34:52 UTC
State Changed
From-To: open->closed


FreeBSD as a rule doesn't make modifications to vendor files. 
5.0-RELEASE will include GCC 3.0, so I guess you'll have to keep 
it locally patched until then.