PixarAnimationStudios / OpenUSD

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

Compiler Warnings: Using the result of a an assignment without parenthesis #3334

Open dgovil opened 1 month ago

dgovil commented 1 month ago

Description of Issue

This is a fairly straightforward style warning that Clang emits that should be a good first issue for someone wanting to get started with building and contributing to USD.

There are a few areas in USD that have an assignment within an if statement that clang recommends wrapping in parenthesis to avoid confusion between assignment or equality comparisons.

I am building with Clang 16 from Xcode 16 using python3 ./build_scripts/build_usd.py ~/Downloads/usd --build-variant debug --no-imaging -vvv but the warning is reproduced below


[1530/4632] Building CXX object pxr/usd/usd/CMakeFiles/usd.dir/primDefinition.cpp.o
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  384 |                 primPath.AppendProperty(propName))) {
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: note: place parentheses around the assignment to silence this warning
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |                      ^
      |             (
  384 |                 primPath.AppendProperty(propName))) {
      |                                                   
      |                                                   )
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: note: use '==' to turn this assignment into an equality comparison
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |                      ^
      |                      ==
1 warning generated.
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  384 |                 primPath.AppendProperty(propName))) {
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: note: place parentheses around the assignment to silence this warning
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |                      ^
      |             (
  384 |                 primPath.AppendProperty(propName))) {
      |                                                   
      |                                                   )
/Users/dhruvgovil/Projects/usd/pxr/usd/usd/primDefinition.cpp:383:22: note: use '==' to turn this assignment into an equality comparison
  383 |         if (destProp = _composedPropertyLayer->GetPropertyAtPath(
      |                      ^
      |                      ==
1 warning generated.
jesschimein commented 1 month ago

Filed as internal issue #USD-10231