string::assign apparent regression

Roberto Bagnara bagnara@cs.unipr.it
Fri Sep 14 04:38:00 GMT 2001


With GCC 3.0.1 and with the latest i686 snapshot distributed
from CodeSourcery, the following simple program prints "merge"
instead of "mergesort_ap_variant.pl", as it should.

GCC versions up to 2.96 are fine.  The problem seems to be in
libstdc++.  In particular, a C-string terminator is written
into the string representation by the following statement in
.../include/g++-v3/bits/basic_string.tcc 

      _M_data()[__new_size] = _Rep::_S_terminal; // grrr. (per 21.3.4)
    // You cannot leave those LWG people alone for a second.


#include <iostream>
#include <string>

using namespace std;

int main() {
  string aux = "../BenchCtiTr/apt/mergesort_ap_variant.pl";
  string::size_type i = aux.rfind("/");
  if (i != string::npos)
    aux.assign(aux, i+1, string::npos);
  cout << aux.c_str() << endl;
}

Please let me know if there is any workaround.
All the best,

     Roberto

-- 
Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@cs.unipr.it



More information about the Gcc-bugs mailing list