Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dgovil opened this issue Oct 2, 2024 · 1 comment
Open
Labels
good first issue Indicates a good issue for first-time contributors

Comments

@dgovil
Copy link
Collaborator

dgovil commented Oct 2, 2024

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.
@dgovil dgovil added the good first issue Indicates a good issue for first-time contributors label Oct 2, 2024
@jesschimein
Copy link

Filed as internal issue #USD-10231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors
Projects
None yet
Development

No branches or pull requests

2 participants