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: Daniel Krügler <daniel dot kruegler at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 11 May 2014 16:34:27 +0200
- 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> <20140509124308 dot GI10556 at redhat dot com> <20140509134605 dot GJ10556 at redhat dot com>
2014-05-09 15:46 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
> Here's a minimal version of the test:
>
> #include <vector>
> #include <cstdlib>
>
> struct C {
> C() { }
> C(const C&) { }
>
> template<class T>
> explicit C(T&) { std::abort(); }
> };
>
> int main() {
> std::vector<C> v(1);
> v.resize(v.capacity()+1);
> }
>
> This aborts with GCC 4.4 in c++03 mode, passes in c++0x mode.
>
> With later releases it passes in c++03 mode, aborts in c++11 mode.
>
> This patch to trunk makes the test pass unchanged in C++11 mode, by
> copying the existing vector elements as const lvalues:
>
> index f4522a4..5d420ba 100644
> --- a/libstdc++-v3/include/bits/stl_iterator.h
> +++ b/libstdc++-v3/include/bits/stl_iterator.h
> @@ -1154,6 +1154,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> __make_move_if_noexcept_iterator(_Iterator __i)
> { return _ReturnType(__i); }
>
> + template<typename _Tp, typename _ReturnType
> + = typename conditional<__move_if_noexcept_cond<_Tp>::value,
> + const _Tp*, move_iterator<_Tp*>>::type>
> + inline _ReturnType
> + __make_move_if_noexcept_iterator(_Tp* __i)
> + { return _ReturnType(__i); }
> +
I cannot deduce the full consequences of this change from here, but
I'm reading 23.3.6.3 p13 that the following example should be
well-formed (C is MoveInsertable and DefaultInsertable):
#include <vector>
struct C {
C() { }
C(C&) { }
C(C&&){}
};
int main() {
std::vector<C> v(1);
v.resize(v.capacity()+1);
}
Would this still hold under that change?
- Daniel