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

Sonar fixes for Iex, IexTest, and ImathTest #575

Merged
merged 3 commits into from
Oct 7, 2019

Conversation

cary-ilm
Copy link
Member

@cary-ilm cary-ilm commented Oct 3, 2019

Various fixes to address SonarCloud "bugs":

  • remove BaseExc::operator= via delete
  • added unit tests for types derived from BaseExc
  • in ImathTest/testFrustum.cpp, don't use a floating-point iterator.

SonarCloud doesn't like floating-point variables in for loops. This
spells out precisely what values are used in the loops.

Signed-off-by: Cary Phillips <[email protected]>
@@ -57,17 +57,17 @@ testFrustumPlanes (IMATH_INTERNAL_NAMESPACE::Frustumf &frustum)
IMATH_INTERNAL_NAMESPACE::V3f o (0.0f, 0.0f, 0.0f);
float eps = 5.0e-4;

for (float xRo = 0.0f; xRo < 360.0f; xRo += 100.0f)
for (auto xRo : {0.0f, 100.0f, 200.0f})
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you need auto instead of float to use this snazzy iteration syntax? It is cool...

Copy link
Contributor

Choose a reason for hiding this comment

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

No you can still explicitly declare the type when using range-based for, so it's fine to declare 'float' here. Do we have a coding standard wrt to usage of auto? For UE4, our standard is that we always explicitly declare the type. The only exceptions where we use 'auto' are when declaring a variable set to a lambda, verbose iterator types, or in template code where the type cannot easily be determined. The advantage of auto's is preventing implicit conversion. But this is only beneficial when auto is used ubiquitously. Here being explicit by declaring the type float seems preferable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we've taken a stance on auto, but when we address it I would prefer the UE4 convention you describe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, I leave it to Cary whether he wants to change this one or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

My vote is also for using the explicit type when it's something that is known and can be written compactly.

float x is better than auto x

But I totally respect auto x when it can replace an ugly mouthful like std:vector<std::pair<FooType,std::map<int>&>::const_iterator.

@cary-ilm
Copy link
Member Author

cary-ilm commented Oct 5, 2019 via email

@kdt3rd
Copy link
Contributor

kdt3rd commented Oct 5, 2019 via email

@lgritz
Copy link
Contributor

lgritz commented Oct 5, 2019

Totally agree with both.

In any kind of range-for based on a container class, I always use [const] auto& -- the type is obligatory based on the container's begin/end return values, and use of auto makes refactoring much easier if the choice of container changes later.

I think this particular idiom of for (auto : { initializer list }) made me nervous because the type can become dependent on exactly how the literals are written. (float, double, or int?) I'm on the fence about that one, but in practice I do use auto very liberally in loops. (Not as big a fan for straight up variable declarations.)

@cary-ilm cary-ilm merged commit f82e198 into AcademySoftwareFoundation:master Oct 7, 2019
@cary-ilm cary-ilm deleted the sonar-fixes branch October 7, 2019 01:38
@cary-ilm cary-ilm added this to the v2.5.0 milestone Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants