<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55252>55252</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-analyzer.UndefReturn false positive
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          briangreenery
      </td>
    </tr>
</table>

<pre>
    I think I have run into a false positive with `clang-analyzer-core.uninitialized.UndefReturn`. Here is the code that it warns on. It only warns when compiled with `-stdlib=libc++` on clang 14.

A repro is also here: https://godbolt.org/z/46q734cM3

```
#include <algorithm>

class IntRef
{
public:
    explicit IntRef(int& x) : m_p(&x) {}
        
    int& get() const { return *m_p; }

    int* m_p;
};

bool operator<(IntRef a, IntRef b) {
    return *a.m_p < *b.m_p;
}

void foo(IntRef* values, int size) {
    std::stable_sort(values, values + size);
}
```

And it warns:

```
[warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]]
    int& get() const { return *m_p; }
                       ^
```

It seems like small changes to the code (like changing `get()` to return `int` instead of `int&`) resolve the warning.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVMGOmzAQ_Rq4jIKICSQ5cEg2u2oOvazUc2VgAu46NrVNstmv7xgISdNVparIgD32zHt-43Ghq0u-B9cI9QZ7aPgJwXQKhHIaOBy4tAittsIJmjkL10CQxaXkqp5xxeXlA82s1AajTglFq7gUH1hF31SFh1d0nVG0PoIvaBCEJSCEUldIHe5AODhzoyxoFcHe0U9eRsu5QUUrj62QWE3AM-sqKYog2dG3DNjWtywmR-g5wXwRBfEuiDfDdwMGW6M9Mu1EQ0M0gmQDjXOtpU7AXqjVuiq0dJE2NY0-6F1kP5fJovya3AcjoLENQ5YIVcqONhMkT1zW2hDLY5A83zsRLWthr9wrHkb7cjt02q6QovQs-iHQg-8tmUiW0YGtKBEBy-A9YGvwzI_fW7KSabBQrOXu5u-f22j0rdH1LmvSU1nnnUgWnxoI2MYHTLYwhXlwHxCT7ZX77tbvv4XWEnSLhjttSAdCGrgDD9jTuA8ormSn4DcCPCIEL6EfFNEj3B3WSYsKDlpPGJ7eicsOrccivmDp9P2BRYfGq5xsrOOFxO9WG6_IzXPoEf72GuATCg_ZH86XqqZDPCXy8_Xp1q8SqvZZ7MtDKDrZ2kDNTcFrHFiMwtAMFWDJpUQD5PtvFZfufPu_cwCfP0H6_Bc9qIYt4tGCFG8I9kj8oWyIOqlL-5mqn3j0K_o50sTX9kTPFzQtvlLLYs-fbIJIIyfJDlcjyzw-bcig1fKEPcAocxRWeVKtkzUPnXAS898lvNfr4ZoLOyPzhxuCKrsrIrqPaCDl6fqb0eXyA0ti8iKs7U_TS5qylIVNniaL5bzI5injMWPpOj4UrCwPSZbyilfrNJS8QGlzym7AmMIz9CGoT8kLRc7IK07jZL5Kk3QdlTFP4zlbrRbVPF4hBosYj1zIyPPwV1do8p5S0dWWJqWwzt4m6RYStULs4Sg-71yjTV4YQaoYRIXmEvYE8n4DvwCWWtJs">