This is the mail archive of the libstdc++-prs@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libstdc++/93: template class basic_string cannot be instantiated with types other than <char>



>Number:         93
>Category:       libstdc++
>Synopsis:       template class basic_string cannot be instantiated with types other than <char>
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 28 11:37:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Joel Roth-Nater
>Release:        2.95.2-51
>Organization:
>Environment:
libgpp.rpm on SuSE-Linux
>Description:
std/bastring.h:334

const charT* c_str () const
  { if (length () == 0) return ""; terminate (); return data (); }

This causes a compiler error if "" (or char*) cannot be
implicitly converted into charT*.
>How-To-Repeat:
instantiate a wide-char version of basic_string:
typedef basic_string<short> wstring;
>Fix:
As a workaround, I created my own version of the header file
which casts "" explicitly to charT*:

std/bastring.h:334

const charT* c_str () const
  { if (length () == 0) return (charT*) L""; terminate (); return data (); }

This will still link with the original lib. I just have to make 
sure I include my header file before anything STL.

It would be cleaner IMO to do this:

static const charT empty_str = 0;
const charT* c_str () const
  { if (length () == 0) return &empty_str; terminate (); return data (); }

>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]