This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Failing test when run as C++11


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]