This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC] libstdc++/8347
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 25 Oct 2002 13:55:50 +0200
- Subject: [RFC] libstdc++/8347
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.