STL bug and patch from 2.95.1
Stuart Yeates
syeates@cs.waikato.ac.nz
Tue Jan 11 14:26:00 GMT 2000
I'm not sure whether I'm reporting this in the right place
or not. There appears to be a oddness in either 2.95.1 or
the STL it ships with. I don't believe the problem's my
fault, if it is, please transmogrify this error message
into a request to improve the error messages.
Using templates, when I try and use a non-standard
basic_string<> variant i get warnings:
========
#include <string>
typedef basic_string <unsigned int> text;
int main()
{
text t;
t.append(0);
return -1;
}
=========
gives the warning:
=========
g++ -g -p -Wall -ansi -pedantic -c dummy.cpp
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3/
std/straits.h: In function `static unsigned int * string_char_
traits<unsigned int>::move(unsigned int *, const unsigned int *, unsigned
int)':
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3/
std/bastring.cc:147: instantiated from `basic_string<unsigne
d int,string_char_traits<unsigned int>,__default_alloc_template<false,0> >
::Rep::move(unsigned int, const unsigned int *, unsigned int)'
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3/
std/bastring.cc:172: instantiated from `basic_string<unsigne
d int,string_char_traits<unsigned int>,__default_alloc_template<false,0> >
::replace(unsigned int, unsigned int, const unsigned int *, unsigne
d int)'
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3/
std/bastring.h:198: instantiated from here
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95.1/../../../../include/g++-3/
std/straits.h:86: warning: ANSI C++ forbids variable-size arra
y `a'
g++ -g -p -Wall -ansi -pedantic -o dummy dummy.o -lm
=========
A simple patch fixes the problem, but introduces a new/delete pair, I'm not
sure this is necessarily a good fix ...
=========
*** straits.h Wed Jan 12 11:21:07 2000
--- straits.h.~1~ Wed Jan 12 11:15:18 2000
***************
*** 83,95 ****
static char_type* move (char_type* s1, const char_type* s2, size_t n)
{
! char_type *a = new char_type[n];
size_t i;
for (i = 0; i < n; ++i)
assign (a[i], s2[i]);
for (i = 0; i < n; ++i)
assign (s1[i], a[i]);
- delete a;
return s1;
}
--- 83,94 ----
static char_type* move (char_type* s1, const char_type* s2, size_t n)
{
! char_type a[n];
size_t i;
for (i = 0; i < n; ++i)
assign (a[i], s2[i]);
for (i = 0; i < n; ++i)
assign (s1[i], a[i]);
return s1;
}
=========
--
-- stuart yeates <s.yeates@cs.waikato.ac.nz> aka `loam'
college is like a fountain of knowledge--and the students are there to drink.
X-no-archive:yes
More information about the Gcc-bugs
mailing list