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 14:46:05 +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> <20140509124308 dot GI10556 at redhat dot 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); }
+
// @} group iterators
_GLIBCXX_END_NAMESPACE_VERSION