Skip to content

Compiler Warnings: Explicit moves to self #3341

@dgovil

Description

@dgovil

Description of Issue

Clang raises a few areas where we are moving the same variable into itself. It would be a good first task for someone new to the project to see if these can be cleaned up or annotated

According to the Clang doc changes, they suggest

The clang release notes suggests:
---
If you are doing such an assignment intentionally, e.g. in a unit test for
a data structure, the warning can be suppressed by adding ``*&`` to the
right-hand side or casting it to the appropriate reference type.
---

Firefox have a similar discussion here https://bugzilla.mozilla.org/show_bug.cgi?id=1453610

I am building with Clang 16 from Xcode 16 with python3 ./build_scripts/build_usd.py ~/Downloads/usd --build-variant debug --no-imaging -vvv but this should reproduce with other compilers. The warnings are reproduced below:

[3566/4632] Building CXX object pxr/base/tf/CMakeFiles/testTf.dir/testenv/delegatedCountPtr.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/delegatedCountPtr.cpp:172:13: warning: explicitly moving variable of type 'TfTestDelegatedCountPtr' (aka 'TfDelegatedCountPtr<RefCountedValue>') to itself [-Wself-move]
  172 |     adopted = std::move(adopted);
      |     ~~~~~~~ ^           ~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/delegatedCountPtr.cpp:228:10: warning: explicitly assigning value of variable of type 'TfDelegatedCountPtr<RefCountedValue>' to itself [-Wself-assign-overloaded]
  228 |     made = made;
      |     ~~~~ ^ ~~~~
2 warnings generated.
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/delegatedCountPtr.cpp:172:13: warning: explicitly moving variable of type 'TfTestDelegatedCountPtr' (aka 'TfDelegatedCountPtr<RefCountedValue>') to itself [-Wself-move]
  172 |     adopted = std::move(adopted);
      |     ~~~~~~~ ^           ~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/base/tf/testenv/delegatedCountPtr.cpp:228:10: warning: explicitly assigning value of variable of type 'TfDelegatedCountPtr<RefCountedValue>' to itself [-Wself-assign-overloaded]
  228 |     made = made;
      |     ~~~~ ^ ~~~~
2 warnings generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIndicates a good issue for first-time contributorshelp wantedIndicates an issue where help and/or a pull request from the community would be very welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions