<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - padding in nested std::pair"
   href="https://bugs.llvm.org/show_bug.cgi?id=40230">40230</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>padding in nested std::pair
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>maxime.arthaud@nasa.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi everyone,

I am getting a weird padding at the beginning of a std::pair.

See the following example:

#include <cstdio>
#include <utility>

int main() {
  std::pair< std::pair< char, char >, char > p;
  printf("%lu %p %p\n", sizeof(p), &p, &p.first);
  return 0;
}

Output:
4 0x7fffffffe738 0x7fffffffe739

There is an additional byte at the beginning of the pair, for no reason. This
is not really a bug, but is worth improving.

It causes crashes in boost::container::flat_map, see
<a href="https://github.com/boostorg/container/issues/97">https://github.com/boostorg/container/issues/97</a>

Please note that this only happens on FreeBSD.

System: FreeBSD 12.0
Compiler: Clang 6.0.1 (default compiler on FreeBSD)
libc++: master branch on Github

I'm pretty sure this is related to <a href="https://reviews.llvm.org/D25389">https://reviews.llvm.org/D25389</a>
The base class __non_trivially_copyable_base introduces the padding. I don't
understand why Empty Base Optimization doesn't work in that case.

To reproduce this, I used the following virtual machine:
<a href="https://download.freebsd.org/ftp/releases/VM-IMAGES/12.0-RELEASE/amd64/Latest/">https://download.freebsd.org/ftp/releases/VM-IMAGES/12.0-RELEASE/amd64/Latest/</a>

Upstream issue in IKOS: <a href="https://github.com/NASA-SW-VnV/ikos/issues/22">https://github.com/NASA-SW-VnV/ikos/issues/22</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>