<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80693>80693</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] bugprone-use-after-move wrong warning within implementation of move constructor
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
SunBlack
</td>
</tr>
</table>
<pre>
Given following code:
```cpp
#include <utility>
class External{};
class External2{};
class A
{
public:
A()
: MyObj(new External) {
}
A(A&& other)
{
std::swap(MyObj, other.MyObj);
};
~A() {
delete MyObj;
};
protected:
External* MyObj;
};
class B : public A
{
public:
B()
: MyObj2(new External2) {
}
B(B&& other)
: A(std::move(other))
{
std::swap(MyObj2, other.MyObj2);
};
~B() {
delete MyObj2;
};
protected:
External2* MyObj2;
};
```
This code causes:
```
test.cpp:36:23: warning: 'other' used after it was moved [bugprone-use-after-move]
36 | std::swap(MyObj2, other.MyObj2);
| ^
test.cpp:34:7: note: move occurred here
34 | : A(std::move(other))
| ^
```
I think this is a false-positve, as `MyObj2` should be still valid after the parent class was moved as the parent class cannot move this.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyclc2SozYQx59GXLrswi0-zIED2ONUDqkckhcQ0AbtyhIliXHmkmdP8WGbmfHWbqbKBZKl7v73r9VIOCdbTZSzuGTxMRCD74zN_xp0qUT9PahM85b_Jl9Jw9koZa5St1CbhhgvWHhk4e2ZhPOv7vvlH-RS12poCBg_DF4q6d8Yf1lb1Uo4By__eLJaKJaWLD0yXj5bxA-r6z03Demy1g-VkvVdIUDBcM8wW6aMF_DH25_VN4Z7TddHfMzg7gNgjLYKNXspGCYMEzC-I_twubJzvhkj88JdRc9wv0Q6zCbbZZrdE5kDrWbL-99F9FoSQEOKPC3yn7vorfFUe2pWAB4pFh9sPzNdky0nWDPPn2Mu32EGeJDGD6jxfWKfUI-eyh-gnt2OdO6oL-aVGO7vO3-5LvihMPhLlSl_Vhn8QmnwXht8Xpxbh61J_d1JN7Uj1GJw5B5d-X63J-e3Y2vygieMF8hHhldhtdTtOGSYLvRSGBw1IM6eLEgPV-Fg5NsAi8tqaHtrNG0GR5tpy2ZiHx_vIHgCLD18CfdU2_QALH75LDtivEhHqdr48esziQJT14O11EBHlh4aosnP_zwrt_DL6CbiKfjfwXdSfx-fDqQDAWehHG1646QfAxxAOGBJuOSZhOA6M6gGKgLnpVLwKpS8cfYdQS8saQ9z4z2oC_d5tRZaGz8TGBVsgybnTcYzEVC-S8N0FyVRmgVdvseIU1rF56zKzhhyHlWY8Xh_bvYJj7AKZI4hRiGG8S7G3W63jWoRVWKXJgJ5yrOGRSFdhFRbpV4vW2PbQDo3UL4Pk4wHSlSk3HR7INZK6HbjZfPGEMfbxOaj0aYaWseiUEnn3cONl15N987KLD7CD44YXK3R7e3IwlWO_EFeekUX0l54aTSY88ykNtp5O9Te2GCwKu-876fewBPDUyt9N1Tb2lwYnkY5y2vTW_ONas_wNKXoGJ6mLP8LAAD__2TAAPU">