<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 is too strict on object lifetime for automatic storage duration"
   href="https://bugs.llvm.org/show_bug.cgi?id=48732">48732</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang is too strict on object lifetime for automatic storage duration
          </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>other
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>minatsuh@microsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Behavior displayed in <a href="https://godbolt.org/z/n5Wenn">https://godbolt.org/z/n5Wenn</a>

Reproducing code repeated here: 
template <typename T>
constexpr void f(T& t) {
    t.~T();
}

struct S {
    constexpr ~S() { }
};

constexpr int g() {
    {
        // This should be fine, provided there are no more reads of
        // 'i' before a new object lifetime is created.
        int i = 0;
        f(i);
    }
    {
        // This should be UB: S::~S() is a non-trivial dtor.
        S s{};
        f(s);
    }
    return 0;
}

static_assert(g() == 0);

Relevant Standardese: 
* <a href="http://eel.is/c++draft/basic.life#5">http://eel.is/c++draft/basic.life#5</a> 
* <a href="http://eel.is/c++draft/basic.life#9">http://eel.is/c++draft/basic.life#9</a>

Currently, Clang errors on the first block of code using int i, though I
believe the first block of code should be fine as int does not have a
non-trivial destructor (<a href="http://eel.is/c++draft/basic.life#9">http://eel.is/c++draft/basic.life#9</a>).  Note that the
second block should produce an error (which Clang does) as struct S does have a
non-trivial destructor.</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>