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

    <tr>
        <th>Summary</th>
        <td>
            [Clang-Tidy] readability-use-std-min-max should consider `std::clamp`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            clang-tidy
      </td>
    </tr>

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

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

<pre>
    Tried the new check `readability-use-std-min-max` of the upcoming Clang-Tidy 19.

In one case we had following code:
```cpp
if (ratio < 0.0F)
{
        ratio = 0.0F;
}
if (ratio > 1.0F)
{
        ratio = 1.0F;
}
```

Running `run-clang-tidy-19  -header-filter='.*' -checks='-*,readability-use-std-min-max' -fix` results in:
```cpp
ratio = std::max(ratio, 0.0F);
ratio = std::min(ratio, 1.0F);
```

But in this case it would be better
```cpp
ratio = std::clamp(ratio, 0.0F, 1.0F);
```

I don't know how complex it would be to recognize this pattern, i.e. whether it is better to introduce a `readability-use-std-clamp`, even if this may require a second pass, or whether this can be combined by changing the check to `readability-use-std-min-max-clamp`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVNFyqzYQ_RrxsgMjBJjwwENs1zP3tb0_IKQF1AiJSiK-7td3BHacpm6SGY89s95z9pwjrbj3ajCILan2pDomfAmjde0fi9lrLl6SzspL-9MplBBGBINnECOKFyA76pBL3imtwiVdPKY-yHRSJp34L7KjYPsVsszCTsoMcNDcDOlPJS-QNxmhR0Kft-8fBqxBENwjnBFGLqG3WttzhAkrkRTXTrKj20fM81ZRPRD25HhQFkhxAJrRE2HNtb3e3-Y0t5bj1lLc_qmPj4h-g_xrovwh0ZvG9xZ_X4yJbmJsi0nFmkVQ8pLmDUA6Ipfo0l7pgI4UR8LqjLBnwmpI17z9VkzX4uGz5COkV-sJOPSLDh6U-STAux0fZOwrnleaLQrC7pHenD5CKPMekX9APIxkvwRQBsKo_Hb0KsDZLlpCh9BhiEl8X7PQfJr_q_qbWn6AtIawOsCLsWcY7RmEnWaNv_6lKlhwKOxg1N-4CZ951GniIJVhBucRw4guopS_uogwZYKzchEI_P9WZ3Owo5ELX9GA6rcZE7-Aw78W5SLao7BGwsy9j53Wvc28JmmiUmGnThmU0F1AjNwM8fLFddy2N9gvFvhNTZbItpBN0fAE27xmNG-KosqTsRWdrLoGy7qqOtnnkuWlLOQT52XdNWXeJKpllJW0plVesSanGfZNvxOdYH1Z1QVjpKQ4caUzrV-nzLohUd4v2Db1U1Elmneo_fowMYZm5EbghCYQxgg7EMbuSxRL1TFxbSRKu2XwpKRa-eDv1EEFvT5z93eIVEf4JAPw43rwwhqvJLoY2Yf7tqPJ4nQ7hjD7WGcnwk6DCuPSZcJOhJ3i_OtPOjv7J4pA2Gn16Qk7bVZfW_ZPAAAA__9PyKwr">