[RFC] libstdc++/8347

Paolo Carlini pcarlini@unitus.it
Fri Oct 25 04:54:00 GMT 2002


Hi,

I'm analyzing this PR, which by itself seems not a bug.
This is the testcase:

// ---------
#include <vector>
#include <string>

int main(int argc,char** argv)
{
  std::vector<char> empty;
  std::string empty2(empty.begin(),empty.end());
}
// ---------

which aborts since triggers (basic_string.tcc):


basic_string<_CharT, _Traits, _Alloc>::
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
             forward_iterator_tag)
{
  size_type __dnew = static_cast<size_type>(distance(__beg, __end));

  // NB: Not required, but considered best practice.
  if (__builtin_expect(__beg == _InIter(), 0))
       __throw_logic_error("attempt to create string with null pointer");


However, what I find puzzling is that, as observed by submitter,
the following:

// ---------
#include <vector>
#include <string>

int main(int argc,char** argv)
{
  std::string empty;
  std::string empty2(empty.begin(),empty.end());
}
// ---------

does *not* abort, since _M_mutate ends up being called, not _S_construct.

Now, are there consistency requirements imposing the same behaviour?

Which one, in case?

I agree with submitter than many different implementations of the ISO 
library
do not abort for such constructs (f.i., SUN, STLPort, v2).

Ciao,
Paolo.



More information about the Libstdc++ mailing list