From bba2391c01cd4d418145a9d337cf9d0877cf2e54 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 17 Dec 2021 23:35:38 -0800 Subject: [PATCH] Treat warnings as errors on release mode --- .ci/build.sh | 1 - CMakeLists.txt | 32 ++++++++++++--------- dart/dynamics/detail/DegreeOfFreedomPtr.hpp | 2 +- unittests/regression/test_Issue1231.cpp | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 0c6172f2413a0..9a8fb0148ee74 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -142,7 +142,6 @@ fi cmake .. \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DDART_VERBOSE=ON \ - -DDART_TREAT_WARNINGS_AS_ERRORS=ON \ -DDART_BUILD_EXTRAS=ON \ -DDART_CODECOV=$CODECOV \ ${install_prefix_option} diff --git a/CMakeLists.txt b/CMakeLists.txt index 100bfb8b59beb..2e5d850ea94ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,6 @@ option(DART_ENABLE_SIMD option(DART_BUILD_GUI_OSG "Build osgDart library" ON) option(DART_BUILD_EXTRAS "Build extra projects" OFF) option(DART_CODECOV "Turn on codecov support" OFF) -option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF) # GCC and Clang add ANSI-formatted colors when they detect the output medium is a # terminal. However, this doesn't work in some cases such as when the makefile is @@ -176,9 +175,9 @@ if(MSVC) ) endif() - if(DART_TREAT_WARNINGS_AS_ERRORS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") - endif() + add_compile_options( + $<$>:/WX> + ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /permissive- /Zc:twoPhase-") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO") if(NOT DART_MSVC_DEFAULT_OPTIONS) @@ -199,10 +198,12 @@ if(MSVC) elseif(CMAKE_COMPILER_IS_GNUCXX) - if(DART_TREAT_WARNINGS_AS_ERRORS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fPIC") + add_compile_options( + -Wall + -Wextra + $<$>:-Werror> + -fPIC + ) execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpfullversion -dumpversion OUTPUT_VARIABLE GCC_VERSION) if(GCC_VERSION VERSION_LESS 7.3.0) @@ -224,12 +225,15 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - if(DART_TREAT_WARNINGS_AS_ERRORS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-error=deprecated-declarations") - # Turn warning "deprecated-declarations" into an warning even if -Werror is - # specified until we abandon glut. - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + add_compile_options( + -Wall + -Wextra + $<$>:-Werror> + $<$>:-Wno-error=deprecated-declarations> + -fPIC + ) + # Turn warning "deprecated-declarations" into an warning even if -Werror is + # specified until we abandon glut. execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION) if(CLANG_VERSION VERSION_LESS 6.0) diff --git a/dart/dynamics/detail/DegreeOfFreedomPtr.hpp b/dart/dynamics/detail/DegreeOfFreedomPtr.hpp index f04d6fa480f1b..1290326ea9000 100644 --- a/dart/dynamics/detail/DegreeOfFreedomPtr.hpp +++ b/dart/dynamics/detail/DegreeOfFreedomPtr.hpp @@ -218,7 +218,7 @@ class TemplateDegreeOfFreedomPtr TemplateBodyNodePtr mBodyNodePtr; /// Local index of this DegreeOfFreedom within its Joint - std::size_t mIndex; + std::size_t mIndex = 0; }; /// TemplateWeakDegreeOfFreedomPtr is a templated class that enables users to diff --git a/unittests/regression/test_Issue1231.cpp b/unittests/regression/test_Issue1231.cpp index cd7c4311e15aa..44e599913b8cd 100644 --- a/unittests/regression/test_Issue1231.cpp +++ b/unittests/regression/test_Issue1231.cpp @@ -45,7 +45,7 @@ TEST(Issue1231, NoContacts) dart::simulation::WorldPtr world = dart::simulation::World::create(); double x = -0.25; - for (const std::string& name : {"1", "2"}) + for (const auto& name : {"1", "2"}) { const auto skeleton = dart::dynamics::Skeleton::create(name); skeleton->setMobile(false);