PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.11k stars 1.21k forks source link

Compiler Warnings: Explicit moves to self #3341

Open dgovil opened 4 weeks ago

dgovil commented 4 weeks ago

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.
jesschimein commented 4 weeks ago

Filed as internal issue #USD-10238