<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 - clang++ miscompilation while generating copy constructors of classes containing 0-length array"
   href="https://bugs.llvm.org/show_bug.cgi?id=40682">40682</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang++ miscompilation while generating copy constructors of classes containing 0-length array
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>joran.bigalet@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The auto-generated copy constructor of a struct containing a 0-length array
followed by exactly 1 trivially copyable field will not copy the later.
This holds for copy assignments.

Here is a simple example:

===================================================

#include <cstdio>

struct NonTrivial {
    int n;

    NonTrivial& operator=(NonTrivial o) {
        this->n = o.n;
        return *this;
    }
};

struct S {
    NonTrivial _a;  // to force clang to generate a copy assignment constructor
    int ok;  // not mandatory, only to show other trivial fields are still
copied
    int _b[0];
    int bugged;  // not copied by the auto-generated copy assignment
constructor, unless directly followed by another non-trivial field
};

int main() {
    S foo;
    foo.ok = 11;
    foo.bugged = 22;

    S bar;
    bar.ok = 9876;
    bar.bugged = 4321;

    bar = foo;

    printf("%d %d ; %d %d\n", foo.ok, foo.bugged, bar.ok, bar.bugged);
    // expected: 11 22 ; 11 22
    //   output: 11 22 ; 11 4321

    return 0;
}

===================================================</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>