"basic_string" problem in libstdc++
Jason Merrill
jason@cygnus.com
Fri Oct 10 09:22:00 GMT 1997
Here's a fix:
Thu Oct 9 23:24:36 1997 Jason Merrill <jason@yorick.cygnus.com>
* stdexcepti.cc (__out_of_range): New fn.
(__length_error): New fn.
* std/bastring.h (OUTOFRANGE): Fix logic. Use throwing functions.
(LENGTHERROR): Likewise.
Revert Oct 2 changes.
* string: Revert Oct 2 changes.
Index: stdexcepti.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/libstdc++/stdexcepti.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -c -r1.2 -r1.3
*** stdexcepti.cc 1996/09/25 01:02:19 1.2
--- stdexcepti.cc 1997/10/10 06:57:31 1.3
***************
*** 6,8 ****
--- 6,21 ----
#endif
#include <stdexcept>
+
+ // Entry points for string.
+
+ void
+ __out_of_range (const char *s)
+ {
+ throw out_of_range (s);
+ }
+
+ void __length_error (const char *s)
+ {
+ throw length_error (s);
+ }
Index: string
===================================================================
RCS file: /cvs/cvsfiles/devo/libstdc++/string,v
rcsdiff: /cvs/cvsfiles/devo/libstdc++/string,v: warning: Unknown phrases like `dead ...;' are present.
retrieving revision 1.6
retrieving revision 1.7
diff -c -r1.6 -r1.7
*** string 1997/10/02 17:26:27 1.6
--- string 1997/10/10 06:57:32 1.7
***************
*** 5,8 ****
--- 5,13 ----
#include <std/bastring.h>
+ extern "C++" {
+ typedef basic_string <char> string;
+ // typedef basic_string <wchar_t> wstring;
+ } // extern "C++"
+
#endif
Index: std/bastring.h
===================================================================
RCS file: /cvs/cvsfiles/devo/libstdc++/std/bastring.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -c -r1.32 -r1.33
*** std/bastring.h 1997/10/02 17:26:30 1.32
--- bastring.h 1997/10/10 06:57:33 1.33
***************
*** 40,45 ****
--- 40,63 ----
#include <iterator>
+ #ifdef __STL_USE_EXCEPTIONS
+
+ extern void __out_of_range (const char *);
+ extern void __length_error (const char *);
+
+ #define OUTOFRANGE(cond) \
+ do { if (cond) __out_of_range (#cond); } while (0)
+ #define LENGTHERROR(cond) \
+ do { if (cond) __length_error (#cond); } while (0)
+
+ #else
+
+ #include <cassert>
+ #define OUTOFRANGE(cond) assert (!(cond))
+ #define LENGTHERROR(cond) assert (!(cond))
+
+ #endif
+
template <class charT, class traits = string_char_traits<charT> >
class basic_string
{
***************
*** 262,269 ****
reference operator[] (size_type pos)
{ unique (); return (*rep ())[pos]; }
! inline reference at (size_type pos);
! inline const_reference at (size_type pos) const;
private:
void terminate () const
--- 280,295 ----
reference operator[] (size_type pos)
{ unique (); return (*rep ())[pos]; }
! reference at (size_type pos)
! {
! OUTOFRANGE (pos >= length ());
! return (*this)[pos];
! }
! const_reference at (size_type pos) const
! {
! OUTOFRANGE (pos >= length ());
! return data ()[pos];
! }
private:
void terminate () const
***************
*** 358,398 ****
static Rep nilRep;
charT *dat;
};
-
- typedef basic_string <char> string;
- // typedef basic_string <wchar_t> wstring;
-
- #ifdef __STL_USE_EXCEPTIONS
-
- #include <stdexcept>
- #define OUTOFRANGE(cond) \
- do { if (!(cond)) throw out_of_range (#cond); } while (0)
- #define LENGTHERROR(cond) \
- do { if (!(cond)) throw length_error (#cond); } while (0)
-
- #else
-
- #include <cassert>
- #define OUTOFRANGE(cond) assert (!(cond))
- #define LENGTHERROR(cond) assert (!(cond))
-
- #endif
-
- template <class charT, class traits>
- inline basic_string <charT, traits>::reference
- basic_string <charT, traits>::at (size_type pos)
- {
- OUTOFRANGE (pos >= length ());
- return (*this)[pos];
- }
-
- template <class charT, class traits>
- inline basic_string <charT, traits>::const_reference
- basic_string <charT, traits>::at (size_type pos) const
- {
- OUTOFRANGE (pos >= length ());
- return data ()[pos];
- }
#ifdef __STL_MEMBER_TEMPLATES
template <class charT, class traits> template <class InputIterator>
--- 384,389 ----
More information about the Gcc-bugs
mailing list