[PATCH] PR libstdc++/87822 fix layout change for nested std::pair

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] PR libstdc++/87822 fix layout change for nested std::pair

Jonathan Wakely-3
The introduction of the empty __pair_base base class for PR 86751
changed the layout of std::pair<std::pair<...>, ...>. The outer pair and
its first member both have a base class of the same type, which cannot
exist at the same address. This causes the first member to be at a
non-zero offset.

The solution is to make the base class depend on the template
parameters, so that each pair type has a different base class type,
which allows the base classes of the outer pair and its first member to
have the same address.

        PR libstdc++/87822
        * include/bits/stl_pair.h (__pair_base): Change to class template.
        (pair): Make base class type depend on template parameters.
        * testsuite/20_util/pair/87822.cc: New test.

Tested powerpc64le-linux and x86_64-linux, committed to trunk.
Backports to gcc-7 and gcc-8 branches coming ASAP.

This layout change is unfortunately in gcc 6.5 and that branch is now
closed. I'm very sorry :-(



patch.txt (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] PR libstdc++/87822 fix layout change for nested std::pair

Jonathan Wakely-3
On 31/10/18 12:31 +0000, Jonathan Wakely wrote:

>The introduction of the empty __pair_base base class for PR 86751
>changed the layout of std::pair<std::pair<...>, ...>. The outer pair and
>its first member both have a base class of the same type, which cannot
>exist at the same address. This causes the first member to be at a
>non-zero offset.
>
>The solution is to make the base class depend on the template
>parameters, so that each pair type has a different base class type,
>which allows the base classes of the outer pair and its first member to
>have the same address.
>
> PR libstdc++/87822
> * include/bits/stl_pair.h (__pair_base): Change to class template.
> (pair): Make base class type depend on template parameters.
> * testsuite/20_util/pair/87822.cc: New test.
Jakub suggested some more testing, as attached.

Tested powerpc64le-linux and x86_64-linux, committed to trunk.
I'll include this in the backports too.



patch.txt (1K) Download Attachment