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

MSVC: Treat warnings as errors #2619

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

chrisdembia
Copy link
Member

@chrisdembia chrisdembia commented Nov 15, 2019

Brief summary of changes

This PR causes MSVC to treat warnings as errors and checks an additional warning about signed/unsigned integers for consistency with warnings generated by Clang.

I'm making this change to help with a similar change in Moco.

Testing I've completed

Ran all ctests.

CHANGELOG.md (choose one)

  • no need to update because...related to build system.

This change is Reviewable

@chrisdembia chrisdembia requested a review from aymanhab November 15, 2019 02:18
Copy link
Member

@aymanhab aymanhab left a comment

Choose a reason for hiding this comment

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

@chrisdembia Most of these are due to mixing int and size_t, can we use size_t instead of casting whenever possible? Thanks

@chrisdembia
Copy link
Member Author

A while ago, I was trying to figure out the best way to handle the different integer types in loops, and my first thought was to use size_t. But that just moved the warning elsewhere; we can't avoid the cast because we use int throughout Simbody's numeric types, etc. For example, we would need to use simbodyVec[(int)index)] in many places.

So, using int is consistent with Simbody (e.g., https://github.com/simbody/simbody/blob/c6f465bc7de0ca2adaecdbffac6076a173f5a347/Simbody/src/MultibodySystemRep.h#L393).

I also referred to the C++ Core Guidelines: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es107-dont-use-unsigned-for-subscripts-prefer-gslindex.

These guidelines suggest using a different type from a third-party library gsl::index. This is the explanation they give:

The built-in array uses signed subscripts. The standard-library containers use unsigned subscripts. Thus, no perfect and fully compatible solution is possible (unless and until the standard-library containers change to use signed subscripts someday in the future). Given the known problems with unsigned and signed/unsigned mixtures, better stick to (signed) integers of a sufficient size, which is guaranteed by gsl::index.

They suggest sticking to signed integers. I know that int may not be of sufficient size but I'm not sure that's a practical issue for us, considering that Simbody uses int everywhere anyway.

@@ -28,3 +29,5 @@ dependencies/*
# MAC File System files
.DS_Store

/CMakeSettings.json

Copy link
Member

Choose a reason for hiding this comment

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

Are these changes related?

Copy link
Member

@aymanhab aymanhab left a comment

Choose a reason for hiding this comment

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

Reviewed 15 of 15 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @chrisdembia)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants