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


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


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