Bug 58083 - bastring.h:342: .c_str() error for wchar_t template instance
Summary: bastring.h:342: .c_str() error for wchar_t template instance
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 8.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-01-08 04:38 UTC by Need Real Name
Modified: 2007-04-18 16:38 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-01 15:22:54 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Sample file showing compile error for basic_string<wchar_t>.c_str() (270 bytes, text/plain)
2002-01-08 04:42 UTC, Need Real Name
no flags Details
Allow basic_string::c_str to work with all character types (560 bytes, patch)
2003-09-06 01:05 UTC, Matt Seitz
no flags Details | Diff

Description Need Real Name 2002-01-08 04:38:04 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901

Description of problem:
The implementation of the .c_str() member function:
 const charT* c_str () const
 { if (length () == 0) return ""; terminate (); return data (); }
This code is incorrect for basic_string<wchar_t> (should return L"").
Compiler reports error:

/usr/include/g++-3/std/bastring.h: In method `const charT 
*basic_string<charT, traits, Allocator>::c_str () const [with charT = 
__wchar_t, traits = string_char_traits<__wchar_t>, Allocator = 
__default_alloc_template<true, 0>]':
../../src/rules/terms/TermHelper.cpp:138:   instantiated from here
/usr/include/g++-3/std/bastring.h:343: cannot convert `const char *' to 
`const __wchar_t *' in return




Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.
[jfox@localhost cc]$ cat wchar.cc
#include <wchar.h>
#include <stdio.h>
#include <string>

int main(int, char**)
{
   std::basic_string<wchar_t> wsTest(L"This is a test string");
   wchar_t *pwcTest = wsTest.c_str();
   printf("The pointer to the wide character string is %p\n", pwcTest);
   return 0;
}
2.
[jfox@localhost cc]$ make wchar
g++     wchar.cc   -o wchar
wchar.cc: In function `int main (int, char **)':
wchar.cc:8: cannot convert `const __wchar_t *' to `__wchar_t *' in 
initialization
/usr/include/g++-3/std/bastring.h: In method `const charT 
*basic_string<charT, traits, Allocator>::c_str () const [with charT = 
__wchar_t, traits = string_char_traits<__wchar_t>, Allocator = 
__default_alloc_template<true, 0>]':
wchar.cc:8:   instantiated from here
/usr/include/g++-3/std/bastring.h:343: cannot convert `const char *' to 
`const __wchar_t *' in return
make: *** [wchar] Error 1

3.
	

Actual Results:  Compiler error for any use of the c_str() member function on a
wchar_t-typed basic_string<>

Expected Results:  No compiler error.

Additional info:

Seems to work OK on WIN32, Solaris

Comment 1 Need Real Name 2002-01-08 04:42:57 UTC
Created attachment 41972 [details]
Sample file showing compile error for basic_string<wchar_t>.c_str()

Comment 2 Matt Seitz 2003-09-06 01:05:43 UTC
Created attachment 94273 [details]
Allow basic_string::c_str to work with all character types

I am having the same problem with "basic_string<unsigned char>" on Red Hat 7.3
(libstdc++-devel-2.96-113, /usr/include/g++-3/std/bastring.h:343).  The
attached patch fixes this problem.

Comment 3 Matt Seitz 2003-09-06 01:08:44 UTC
The "component" field of this bug report should be changed to "libstdc++".

Comment 4 Benjamin Kosnik 2004-10-01 15:22:54 UTC
This is a feature request: gcc pre 3.0 didn't support wstring.

Testcase is in error: basic_string::c_str() returns 

const _CharT*

not

_CharT*.

With this testcase, gcc-3.2, gcc-3.3, gcc-3.4 pass.

#include <wchar.h>
#include <stdio.h>
#include <string>

int main(int, char**)
{
   std::basic_string<wchar_t> wsTest(L"This is a test string");
   const wchar_t *pwcTest = wsTest.c_str();
   printf("The pointer to the wide character string is %p\n", pwcTest);
   return 0;
}



Note You need to log in before you can comment on or make changes to this bug.