Anton Pevtsov wrote:
The linker error disappears, thanks!

But, unfortunately, the problems with UserTraits members occurred:

Yep, these are more of my screwups. I should have finished the test
before making the changes...


1) char.cpp, line 132, the copy() member function:
...
for (size_t i = 0; i != n; dst [i] = src [i]);
...

This is the endless loop. I think it should be changed to something like
this:
...
for (size_t i = 0; i != n; dst [i] = src [i++]);

This won't work because modifying the same variable (i above) in
the same expression (or, more precisely, between two subsequent
sequence points) has undefined behavior.

...

2) char.cpp, line 146, the move() member function:
...
for (; n--; dst [n] = src [n]);
...

This code doesn't work properly. E.g. move when
dst = "abc", src = "bc", n = 2, dst and src points to the same string,
results in "cc", but "bc" is expected.

I use the following code instead:
...
if (dst < src) {
    while (n--)
        *dst++ = *src++;
}
else {
    for (dst += n, src += n; n--; )
        *--dst = *--src;
}
...

Thanks! I fixed both problems with the commit below:
  http://svn.apache.org/viewcvs?rev=385211&view=rev

The test is here. It still needs to be enhanced to cover the
remaining member functions of UserTraits<UserChar> as well as
the other two specializations of the template. Feel free to
post patches with those enhancements or any other extensions
to it.

  http://svn.apache.org/viewcvs?rev=385210&view=rev

Martin

Reply via email to