This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Failing test when run as C++11
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Daniel Krügler <daniel dot kruegler at gmail dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 9 May 2014 13:43:08 +0100
- Subject: Re: Failing test when run as C++11
- Authentication-results: sourceware.org; auth=none
- References: <20140509105321 dot GD10556 at redhat dot com> <CAGNvRgBEuc1qSiPA41-AiVifoW0aLXYVwQZK+O-SiODxauQDew at mail dot gmail dot com> <20140509112018 dot GE10556 at redhat dot com> <20140509121054 dot GH10556 at redhat dot com> <CAGNvRgB1A0CThLiiPU6zt1Q1ARNwkBeSNiKczbv8t3W-75Fn2w at mail dot gmail dot com>
On 09/05/14 14:30 +0200, Daniel Krügler wrote:
2014-05-09 14:10 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
Sorry, I didn't realise that PR needs authorisation.
It's basically the same code as the 808590.cc testcase saying it works
with GCC 4.5+ but not GCC 4.4, so you're not missing anything
interesting.
If I understand (guessing somewhat on my side) the bug report and the
corresponding test case correctly, it should ensure that in this
scenario the template constructor is not used during the resize
operation in this line:
cbs[fd] = cb;
nor during the default argument evaluation nor within the vector
internals of the resize operation, right? (I'm not sure whether one of
these aspects where considered more important than the other).
The unwanted calls to c::c<c>(c&) happen during vector::resize() when
copying/moving the pre-existing elements to the new storage (which is
why the vector size is chosen to go from 62 to 67, as that triggers a
re-allocation).
The least invasive one would be to (unconditionally) add the throw()
to the copy constructor as you suggested, because this did not affect
C++03 at all. But it seems to me that adding the conditional defaulted
move constructor is more appropriate, because it points more clearly
to the change of semantics during the language update.
My thoughts exactly. The empty throw() works in this specific case,
but isn't feasible for copy constructors in general. In the general
case, adding a nothrow move constructor would be the better fix.
An alternative viewpoint would be that during reallocation vector
should either try to move from rvalues (if that won't throw), or it
should ensure it copies from *const* lvalues (e.g. by using
const_cast). That would need no changes to the testcase and would
avoid the change in behaviour from C++03 to C++11. I'm not sure if
that's allowed by the standard (I think it is) or if that added safety
is really helpful for users.