<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68870>68870</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] add `modernize-use-exchange` check
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
purpleKarrot
</td>
</tr>
</table>
<pre>
Implement a check that can suggests those kind of fixes:
```diff
Foo(Foo&& other) noexcept
- : m_{other.m_}
+ : m_{std::exchange(other.m_, nullptr)}
{
- other.m_ = nullptr;
}
Foo& operator=(Foo&& other) noexcept {
if (this != &other) {
- m_ = other.m_;
- other.m_ = nullptr;
+ m_ = std::exchange(other.m_, nullptr);
}
return *this;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUU82OozwQfJrm0kpkN8GBA4fkiyJ92odYGdyAdwxGtlnN7NOvIDNMDqORVkLmx1VdVU1bx2j7ibmG4grFLdNLGnyo5yXMjn_oEHzKGm_e6v_H2fHIU0KN7cDtC6ZBJ2z1hHHpe44pYhp8ZHyxk0HfYWdfOUJ-AXED8bEq8biM7brHJ7x7D1RuqwJS6NPAAajCyfNry3N64A6IkF9w_Ann6wY5ro-397p0fdqOyay6-YVf20FPPQOVO4X-w2lxbk6rxl4A4XzddT6wCPltB-fXHblzngIo9DMHnXyA_PZ9nk8tRLQdApVpsBGB5CoIpHbKsyvEd0d7lHzf_Nbx1pyd_Q_N-SIyYuC0hAmBLqvpLzD7P368ZqbOTZVXOuNaquosRVEKyoZalFTopjInqaqOOmU6mVemKbQ56Y6FzGxNgnIpJEkh1YmOQjSyaEsjCyWbkyQ4CR61dUfnfo9HH_rMxrhwrcryLDKnG3ZxG2yi1umpPyRr3oBoHfRQr6RDs_QRTsLZmOJnmWST247EE624oTYGQYnRGw6T_cOHJfJhb6MSj4ORLcHVQ0rzNvx0B7r3Ng1Lc2z9CHRfVd5vhzn4X9wmoPvmPALdN_N_AwAA___ewwxG">