Pair trivial move constructor

Paolo Carlini paolo.carlini@oracle.com
Thu Nov 29 11:56:00 GMT 2012


Hi,

just  a quick reply, for sure other have more technical points to make. 
But...

On 11/29/2012 12:26 PM, Christian Rorvik wrote:
> It's my understanding that in GCC 4.7.2 ABI fixes were put in place to
> ensure compatibility between code compiled with/without -std=c++11.
>
> As part of that std::pair's move constructor was made trivial, with
> its current definition:
> constexpr pair(pair&&) = default;
>
> The implication of this appears to be that all types contained in
> std::pair must be either movable or trivially copyable, otherwise the
> compiler will implicitly delete pair's move constructor and then
> complain about its usage. Example:
>
> #include <utility>
>
> struct Foo
> {
>      Foo();
>      Foo(const Foo&);
> };
>
> typedef std::pair<Foo, Foo> FooPair;
>
> FooPair create();
>
> void test()
> {
>      const FooPair x = create();
> }
>
>
> Produces:
>
> a.cpp:15:30: error: use of deleted function 'constexpr std::pair<_T1,
> _T2>::pair(std::pair<_T1, _T2>&&) [with _T1 = Foo; _T2 = Foo;
> std::pair<_T1, _T2> = std::pair<Foo, Foo>]'
> In file included from
> /usr/local/gcc-4.7.2/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/utility:72:0,
>                   from a.cpp:1:
> /usr/local/gcc-4.7.2/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_pair.h:120:17:
> note: 'constexpr std::pair<_T1, _T2>::pair(std::pair<_T1, _T2>&&)
> [with _T1 = Foo; _T2 = Foo; std::pair<_T1, _T2> = std::pair<Foo,
> Foo>]' is implicitly deleted because the default definition would be
> ill-formed:
> /usr/local/gcc-4.7.2/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_pair.h:120:17:
> error: non-static data member 'std::pair<Foo, Foo>::first' does not
> have a move constructor or trivial copy constructor
> /usr/local/gcc-4.7.2/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_pair.h:120:17:
> error: non-static data member 'std::pair<Foo, Foo>::second' does not
> have a move constructor or trivial copy constructor
I can't reproduce this, neither with stock 4.7.2, neither with current 
4_7-branch, neither in mainline. Maybe you have a pasto in the code above?
> I'm not sure how this sits with the standard requirement for
> std::pair,
For sure C++11 wants a defaulted move constructor.

Paolo.



More information about the Libstdc++ mailing list