<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 - Lifetime of temporaries inconsistently extending when optiimzations are enabled"
   href="https://bugs.llvm.org/show_bug.cgi?id=47861">47861</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Lifetime of temporaries inconsistently extending when optiimzations are enabled
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chris@chrissavoie.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>Godbolt example: <a href="https://godbolt.org/z/fssed1">https://godbolt.org/z/fssed1</a>

The following code:
struct A {
    __attribute__((noinline))
    A(int i) : data(i) {}
    A& operator+=(int i) { data += i; return *this; }
    int data;
};

int main() {
    A const& b = A(5) += 5;
    A c(6);
    return b.data + c.data; // 16 expected
}

Will return 16 when compiled without optimizations, 11 when compiled with
optimizations (-O2 or greater).

Browsing versions on godbolt it looks like the difference appeared between
versions 6.0.0 and 7.0.0.

I realize that this is generally undefined behavior, but the differences
between optimization levels caught me off guard. I'm not sure if there's either
a way to return to the pre-7 behavior or to make the non-optimized version more
obviously incorrect.</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>