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

COMP: Fix Unitialized scenarios #4672

Conversation

andrei-sandor
Copy link
Contributor

@andrei-sandor andrei-sandor commented May 16, 2024

This is to fix the -Wconditional-uninitialized warning from clang. The compiler produces this warning in the following scenarios.

  1. Variable is declared. Used inside a try clause and processed after the try/catch clause.
  2. Variable is declared and used inside a if statement

For scenario 1, for itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxxTo, the compiler complains about movingImageValue. This variable is declared and used inside the try clause. After the try clause, it is used. The compiler doesn't seem to catch that it is used in the try clause. To fix scenario 1, the code after the try/catch clause is brought inside the try statement. The two blocks depend on pointIsValid which is used inside the if statements. Hence, everything is found inside the try and the compiler doesn't complain about uninitialized while respecting the logic of the if statements and respecting the catch clause.

To fix scenario 2, the variable will be set to 0.0 which seems to be the easiest fix. Since the variable is processed inside if statements, setting to 0.0 is the easiest fix to solve the uninitialized problem.

@github-actions github-actions bot added type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module labels May 16, 2024
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but clang-format needs to be applied.

These involve setting variables to 0.0 or moving blocks of code inside try clauses
@thewtex thewtex merged commit 10d11d6 into InsightSoftwareConsortium:master May 22, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants