<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 - Missing returned object destructor call after exception throw"
   href="https://bugs.llvm.org/show_bug.cgi?id=51523">51523</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing returned object destructor call after exception throw
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mbtrash@yandex.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>14.3.2 Exception handling:Constructors and destructors:2
(<a href="https://eel.is/c++draft/except.ctor#2">https://eel.is/c++draft/except.ctor#2</a>)
says
"If an exception is thrown during the destruction of temporaries or local
variables for a return statement ([stmt.return]), the destructor for the
returned object (if any) is also invoked"

And it contains example (<a href="https://eel.is/c++draft/except.ctor#example-1">https://eel.is/c++draft/except.ctor#example-1</a>) with
description
"...the local variable y is destroyed, causing stack unwinding, resulting in
the destruction of the returned object, ..."

Trying to recreate this example with following code

#include <iostream>
using namespace std;

struct S{
  int i = 123;
  S(int i) :i(i) {cout<<"S("<<i<<")"<<endl;}
  ~S() {cout<<"~S("<<i<<")"<<endl;}
};

struct T {
  T() {cout<<"T()"<<endl;}
  ~T() noexcept(false) {
    cout<<"~T()"<<endl;
    throw 0;
  }
};

S foo() {
  try {
    T t;
    return {3};
  } catch (...){}
  return {4};
}

int main() {
  foo();
}

Output doesn't have S{3}'s (returned object) destruction line:
T()
S(3)
~T()
S(4)
~S(4)

while should be
T()
S(3)
~T()
~S(3) <-----!
S(4)
~S(4)

Link to godbolt:
<a href="https://godbolt.org/z/YrasqsvMe">https://godbolt.org/z/YrasqsvMe</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>