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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
tmp
# Ignore build trees.
/build*
/out
# CLion integrated development environment
/cmake-build-*
# Ignore install dir.
Expand All @@ -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?

2 changes: 1 addition & 1 deletion Applications/opensense/opensense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void addImuFramesFromMarkers(const string& modelFile, const string& markersFile)
// store joint initial pose from marker IK as default pose for the model.
model.setPropertiesFromState(s);

for (int i = 0; i < offsets.size(); ++i) {
for (int i = 0; i < (int)offsets.size(); ++i) {
// add imu offset frames to the model with model taking ownership
bodies[i]->addComponent(offsets[i]);
}
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ if(WIN32 AND ${CMAKE_C_COMPILER} MATCHES "cl")
set(mxcpu ${BUILD_LIMIT_PARALLEL_COMPILES}) # abbreviation

## C++
# Disable "C4068: unknown pragma" warning.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068")
set(CMAKE_CXX_FLAGS_DEBUG
"/MP${mxcpu} /D _DEBUG /MDd /Od /Ob0 /RTC1 /Zi /bigobj /GS- ${CL_INST_SET}"
CACHE STRING "VC++ Debug build compile flags" FORCE)
Expand Down Expand Up @@ -388,6 +386,13 @@ if(WIN32 AND ${CMAKE_C_COMPILER} MATCHES "cl")
"/MP${mxcpu} /D NDEBUG /MD /O1 /Ob1 /Oi /GS- ${CL_INST_SET}"
CACHE STRING "VC++ MinSizeRel build compile flags" FORCE)

# Treat warnings as errors.
# Ideally we would increase the warning level to 4 but that generates
# warnings in our dependencies.
# Convert warning 4388 ('operator' signed/unsigned mismatch) from
# level 4 to level 3 for consistency with Clang.
add_compile_options(/WX /w34388) # /W4

endif()

set(BUILD_JAVA_WRAPPING OFF CACHE BOOL "Build Java wrapping (needed if you're building the GUI or the Matlab wrapping; requires that you have SWIG and Java installed on your machine.)")
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Auxiliary/auxiliaryTestFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ASSERT_EQUAL( const Container& vecA,
throw OpenSim::Exception(message, file, line);
}
else {
for (auto i = 0; i < vecA.size(); ++i) {
for (int i = 0; i < (int)vecA.size(); ++i) {
// if both values are NaN treat them as being equivalent
if ( SimTK::isNaN(vecA[i]) && SimTK::isNaN(vecB[i]) )
continue;
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/APDMDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void APDMDataReader::find_start_column(std::vector<std::string> tokens,
found_index = static_cast<int>(std::distance(tokens.begin(), it));
// now check the following indices for match with remaining search_labels
bool match = true;
for (int remaining = 1; remaining < search_labels.size() && match; remaining++) {
for (int remaining = 1; remaining < (int)search_labels.size() && match; remaining++) {
match = tokens[found_index + remaining].
compare(sensorName + search_labels[remaining]) == 0;
}
Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Common/ComponentSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void AbstractSocket::prependComponentPathToConnecteePath(
ComponentPath path(getConnecteePath(iConn));
if (path.isAbsolute()) {
ComponentPath newPath(pathToPrepend);
for (int iPath = 0; iPath < path.getNumPathLevels();
for (int iPath = 0; iPath < (int)path.getNumPathLevels();
++iPath) {
newPath.pushBack(
path.getSubcomponentNameAtLevel(iPath));
Expand All @@ -71,7 +71,7 @@ void AbstractInput::prependComponentPathToConnecteePath(
ComponentPath path(componentPath);
if (path.isAbsolute()) {
ComponentPath newPath(pathToPrepend);
for (int iPath = 0; iPath < path.getNumPathLevels();
for (int iPath = 0; iPath < (int)path.getNumPathLevels();
++iPath) {
newPath.pushBack(
path.getSubcomponentNameAtLevel(iPath));
Expand Down
6 changes: 3 additions & 3 deletions OpenSim/Common/DataTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ class DataTable_ : public AbstractDataTable {
InvalidArgument,
"Column-label '" + columnLabel + "' already exists in "
"the DataTable.");
OPENSIM_THROW_IF(depCol.nrow() != getNumRows(),
OPENSIM_THROW_IF(depCol.nrow() != (int)getNumRows(),
IncorrectNumRows,
static_cast<size_t>(getNumRows()),
static_cast<size_t>(depCol.nrow()));
Expand Down Expand Up @@ -1223,10 +1223,10 @@ class DataTable_ : public AbstractDataTable {
DataTable_(const std::vector<ETX>& indVec,
const SimTK::Matrix_<ETY>& depData,
const std::vector<std::string>& labels) {
OPENSIM_THROW_IF(indVec.size() != depData.nrow(), InvalidArgument,
OPENSIM_THROW_IF((int)indVec.size() != depData.nrow(), InvalidArgument,
"Length of independent column does not match number of rows of "
"dependent data.");
OPENSIM_THROW_IF(labels.size() != depData.ncol(), InvalidArgument,
OPENSIM_THROW_IF((int)labels.size() != depData.ncol(), InvalidArgument,
"Number of labels does not match number of columns of "
"dependent data.");

Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/DelimFileAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ DelimFileAdapter<T>::extendRead(const std::string& fileName) const {

auto row_vector = readElems(row);

OPENSIM_THROW_IF(row_vector.size() != column_labels.size(),
OPENSIM_THROW_IF(row_vector.size() != (int)column_labels.size(),
RowLengthMismatch,
fileName,
line_num,
Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Common/Test/testAPDMDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main() {
std::vector<std::string> imu_names{ "torso", "pelvis", "shank" };
std::vector<std::string> names_in_experiment{ "Static", "Upper", "Middle" };
// Programmatically add items to name mapping, write to xml
for (int index = 0; index < imu_names.size(); ++index) {
for (int index = 0; index < (int)imu_names.size(); ++index) {
ExperimentalSensor nextSensor(names_in_experiment[index], imu_names[index]);
readerSettings.append_ExperimentalSensors(nextSensor);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ void testAPDMFormat7() {
std::vector<std::string> imu_names{ "imu1", "imu2", "imu4" };
std::vector<std::string> names_in_experiment{ "Lumbar", "Right Ankle", "Right Foot" };
// Programmatically add items to name mapping, write to xml
for (int index = 0; index < imu_names.size(); ++index) {
for (int index = 0; index < (int)imu_names.size(); ++index) {
ExperimentalSensor nextSensor(names_in_experiment[index], imu_names[index]);
readerSettings.append_ExperimentalSensors(nextSensor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/Test/testXsensDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main() {
std::vector<std::string> imu_names{ "shank", "thigh" };
std::vector<std::string> file_names{ "000_00B421AF", "000_00B4227B" };
// Programmatically add items to Map, write to xml
for (int index = 0; index < imu_names.size(); ++index) {
for (int index = 0; index < (int)imu_names.size(); ++index) {
ExperimentalSensor nextSensor(file_names[index], imu_names[index]);
readerSettings.append_ExperimentalSensors(nextSensor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Simulation/Model/ExternalLoads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void ExternalLoads::transformPointsExpressedInGroundToAppliedBodies(
}
// Once we've transformed the forces (done with computation),
// then replace them in the Set
for (int i = 0; i < transformedForces.size(); ++i) {
for (int i = 0; i < (int)transformedForces.size(); ++i) {
ExternalForce *transformedExf = transformedForces[i];
if (transformedExf) {
set(i, transformedExf);
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Simulation/OpenSense/InverseKinematicsStudy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void InverseKinematicsStudy::
std::cout << "press any key to visualize experimental marker data ..." << std::endl;
std::cin >> c;

for (size_t j =startEnd[0]; j <= startEnd[1]; j=j+10) {
for (int j =startEnd[0]; j <= startEnd[1]; j=j+10) {
std::cout << "time: " << times[j] << "s" << std::endl;
state.setTime(times[j]);
previewWorld.realizePosition(state);
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Simulation/OpenSense/OpenSenseUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TimeSeriesTable_<SimTK::Rotation> OpenSenseUtilities::
SimTK::Matrix_<SimTK::Rotation> matrix(int(nt), nc, Rotation());

int cnt = 0;
for (size_t i = startEnd[0]; i <= startEnd[1]; ++i) {
for (int i = startEnd[0]; i <= startEnd[1]; ++i) {
newTimes[cnt] = times[i];
const auto& quatRow = quaternionsTable.getRowAtIndex(i);
for (int j = 0; j < nc; ++j) {
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Simulation/SimulationUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void OpenSim::updateSocketConnecteesBySearch(Model& model)
int numSocketsUpdated = 0;
for (auto& comp : model.updComponentList()) {
const auto socketNames = comp.getSocketNames();
for (int i = 0; i < socketNames.size(); ++i) {
for (int i = 0; i < (int)socketNames.size(); ++i) {
auto& socket = comp.updSocket(socketNames[i]);
try {
socket.finalizeConnection(model);
Expand Down
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ build_script:
# for some reason.
- cd %OPENSIM_BUILD_DIR%
# Configure. # TODO -DBUILD_SIMM_TRANSLATOR=ON
# Set the CXXFLAGS environment variable to turn warnings into errors.
# Skip timing test section included by default
- cmake -E env CXXFLAGS="/WX -DSKIP_TIMING" cmake %OPENSIM_SOURCE_DIR% -G"%CMAKE_GENERATOR%" -T"%CMAKE_TOOLSET%" -DSIMBODY_HOME=C:\simbody%NUGET_PACKAGE_ID_SUFFIX% -DOPENSIM_DEPENDENCIES_DIR=%OPENSIM_DEPENDENCIES_INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%OPENSIM_INSTALL_DIR% -DBUILD_JAVA_WRAPPING=ON -DBUILD_PYTHON_WRAPPING=ON -DWITH_BTK:BOOL=ON
- cmake -E env CXXFLAGS="-DSKIP_TIMING" cmake %OPENSIM_SOURCE_DIR% -G"%CMAKE_GENERATOR%" -T"%CMAKE_TOOLSET%" -DSIMBODY_HOME=C:\simbody%NUGET_PACKAGE_ID_SUFFIX% -DOPENSIM_DEPENDENCIES_DIR=%OPENSIM_DEPENDENCIES_INSTALL_DIR% -DCMAKE_INSTALL_PREFIX=%OPENSIM_INSTALL_DIR% -DBUILD_JAVA_WRAPPING=ON -DBUILD_PYTHON_WRAPPING=ON -DWITH_BTK:BOOL=ON

# Build.
- cmake --build . --config Release -- /maxcpucount:4 /verbosity:quiet #/p:TreatWarningsAsErrors="true"
- cmake --build . --config Release -- /maxcpucount:4 /verbosity:quiet

test_script:
## Run tests.
Expand Down