<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 - Warn when saving a pointer to an object with temporary lifetime"
   href="https://bugs.llvm.org/show_bug.cgi?id=51002">51002</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Warn when saving a pointer to an object with temporary lifetime
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </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>josephcsible@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this C code:

typedef struct {
    int x[1];
} foo;

foo f(void);

int g(void) {
    int *p = f().x;
    return *p;
}

The g() function is always UB, since the return value of f() has temporary
lifetime, so doing "return *p;" is dereferencing a pointer to an object whose
lifetime has ended. (This is the case both before and after C11's change to
temporary lifetime.) Since it's obvious at compile time that p can never be
used safely, we should have a warning for it, similar to how we have
-Wreturn-stack-address to catch mistakes like this function:

int *h(void) {
    int x;
    return &x;
}</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>