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

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] false-negative in bugprone-return-const-ref-from-parameter when overload for rvalues exists with different constness
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy,
            false-negative
      </td>
    </tr>

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

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

<pre>
    This is a followup bug of #90274.

The following code snippet should generate `bugprone-return-const-ref-from-parameter` error but clang-tidy doesn't:

```cpp
#include <string>

struct Foo {
  const std::string &f(const std::string &a) const {
    return a;
  }
  void f(std::string&&) = delete;
};
```

The following bug-prone usage compiles:

```cpp
int main() {
  const Foo foo;
  auto& a = foo.f(std::string("12"));
  // use a...
  return 0;
}
```

The proper way to avoid this clang-tidy warning is to overload with the same constness:

```cpp
#include <string>

struct Foo {
  const std::string &f(const std::string &a) const {
    return a;
  }
  void f(std::string&&) const = delete;
};
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVN1uozwQfZrhZgRyTPi74CJtvjxBX8DgAfzJ2Mg_Sfv2KyBR2lWr3duVRnIyzBzPORxGeK9GQ9RC8QLFORExTNa173GSdE06Kz_at0l5VB4FDlZre4sLdnFEOyDwvGG8OmbATsBObxPdS5QZsbeS0Bu1LBTQTzZqiSMZciIQQsm6OC7OGkodhehM2lvjQ-poSAdn53QRTswUyEHJkJyzDrsYsNfCjGlQ8gOlJW-AVwHy0z4AlGyPflnWvzxXptdREkL-6oNTZoT8v73WBxf7gBdrEaoXYCfEbQL0Qa6A-WlvQODlALz-8aEA3txbH0CIOycUkO8ZqM7bebVK4gr3GxDwcosGIT-jJE2B9t61c__xIPed2F0c001NjF6MhL2dF6XJ_ySNMgFnoQzwerv0iwKrJoO1j9lFDBZ4iWKbbbA2-5ZADZwfOHAOvFnjwZxfgF8wekKRZdmWu6vDngy_pbc4u5DDm_jAYFFs2oXVjJ9McBPOrAIov9bYKzlthcSbChOGidCLmXZahvyPcvyTTrkj_dEviWxz2eSNSKg9VEVdVU1d1MnUFkNddhWrWFnXvMsrUXcyrw6FHFjXD1WRqJYzXrCGF6woqrzODoLJ_iDqQ1N2R14wODKahdKZ1tc5s25MlPeR2kPJyoIlWnSk_bZaOH--tM0jr8D5ILSn1NAogrrSmi7OiWtXsLSLo4cj08oH_4QPKuhtV31CK874FQiVwb_dLnibyDx9M1iH7ip0JI_0vt69W0mqYSBHJjy9lESn2ymEZXPV5vJRhSl2WW9n4Jd15vuxfpr_Ux-AXzZ9PPDLXaJry38FAAD__8qxsW4">