From f4be42d8923a455bcfff336483bf65a66f3e4983 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 2 Oct 2018 20:51:33 -0700 Subject: [PATCH] Enable -Werror build for clang on Circle CI --- .circleci/config.yml | 37 ++++++++++++------- CMakeLists.txt | 4 ++ cmake-utils/utils.cmake | 12 ++++-- src/cpp-utils/assert/backtrace_nonwindows.cpp | 3 ++ src/cpp-utils/process/subprocess.cpp | 3 ++ 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c98e2754..2930b33e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -377,17 +377,28 @@ jobs: BUILD_TYPE: "Release" CMAKE_FLAGS: "" RUN_TESTS: true -# clang_werror: -# <<: *job_definition -# environment: -# CC: clang-7 -# CXX: clang++-7 -# BUILD_TOOLSET: clang -# APT_COMPILER_PACKAGE: clang-7 -# CXXFLAGS: "-Werror" -# BUILD_TYPE: "Release" -# CMAKE_FLAGS: "" -# RUN_TESTS: false + clang_werror: + <<: *job_definition + environment: + CC: clang-7 + CXX: clang++-7 + BUILD_TOOLSET: clang + APT_COMPILER_PACKAGE: clang-7 + CXXFLAGS: "" + BUILD_TYPE: "Release" + CMAKE_FLAGS: "-DUSE_WERROR=on" + RUN_TESTS: false + gcc_werror: + <<: *job_definition + environment: + CC: gcc-8 + CXX: g++-8 + BUILD_TOOLSET: gcc + APT_COMPILER_PACKAGE: "g++-8" + CXXFLAGS: "" + BUILD_TYPE: "Release" + CMAKE_FLAGS: "-DUSE_WERROR=on" + RUN_TESTS: false gcc_werror: <<: *job_definition environment: @@ -484,8 +495,8 @@ workflows: <<: *enable_for_tags - clang_7_release: <<: *enable_for_tags -# - clang_werror: -# <<: *enable_for_tags + - clang_werror: + <<: *enable_for_tags - gcc_werror: <<: *enable_for_tags - no_compatibility: diff --git a/CMakeLists.txt b/CMakeLists.txt index 7566a23d..0c4ba6cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,13 @@ require_clang_version(4.0) option(BUILD_TESTING "build test cases" OFF) option(CRYFS_UPDATE_CHECKS "let cryfs check for updates and security vulnerabilities" ON) option(DISABLE_OPENMP "allow building without OpenMP libraries. This will cause performance degradations." OFF) + +# The following options are helpful for development and/or CI +option(USE_WERROR "build with -Werror flag") option(USE_CLANG_TIDY "build with clang-tidy checks enabled" OFF) option(CLANG_TIDY_WARNINGS_AS_ERRORS "treat clang-tidy warnings as errors" OFF) + if (MSVC) option(DOKAN_PATH "Location of the Dokan library, e.g. C:\\Program Files\\Dokan\\DokanLibrary-1.1.0" "") endif() diff --git a/cmake-utils/utils.cmake b/cmake-utils/utils.cmake index 6c79440a..4054723f 100644 --- a/cmake-utils/utils.cmake +++ b/cmake-utils/utils.cmake @@ -56,12 +56,18 @@ endif() # Uses: target_enable_style_warnings(buildtarget) ################################################# function(target_enable_style_warnings TARGET) - # Enable compiler options - if (NOT MSVC) - # TODO Add compiler warnings on MSVC + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # TODO + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align -Wno-unused-command-line-argument) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others? + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others? endif() + if (USE_WERROR) + target_compile_options(${TARGET} PRIVATE -Werror) + endif() + # Enable clang-tidy if(USE_CLANG_TIDY) set_target_properties( diff --git a/src/cpp-utils/assert/backtrace_nonwindows.cpp b/src/cpp-utils/assert/backtrace_nonwindows.cpp index 6bc54dd0..8e26df5a 100644 --- a/src/cpp-utils/assert/backtrace_nonwindows.cpp +++ b/src/cpp-utils/assert/backtrace_nonwindows.cpp @@ -97,9 +97,12 @@ namespace { } void set_handler(int signum, void(*handler)(int)) { auto result = signal(signum, handler); +#pragma GCC diagnostic push // SIG_ERR uses old style casts +#pragma GCC diagnostic ignored "-Wold-style-cast" if (SIG_ERR == result) { LOG(ERR, "Failed to set signal {} handler. Errno: {}", signum, errno); } +#pragma GCC diagnostic pop } } diff --git a/src/cpp-utils/process/subprocess.cpp b/src/cpp-utils/process/subprocess.cpp index 60520e22..c1eb1a9e 100644 --- a/src/cpp-utils/process/subprocess.cpp +++ b/src/cpp-utils/process/subprocess.cpp @@ -57,11 +57,14 @@ namespace cpputils { if (returncode == -1) { throw std::runtime_error("Error calling pclose. Errno: " + std::to_string(errno)); } +#pragma GCC diagnostic push // WIFEXITSTATUS / WEXITSTATUS use old style casts +#pragma GCC diagnostic ignored "-Wold-style-cast" if (!WIFEXITED(returncode)) { // WEXITSTATUS is only valid if WIFEXITED is 0. throw std::runtime_error("WIFEXITED returned " + std::to_string(WIFEXITED(returncode))); } return WEXITSTATUS(returncode); +#pragma GCC diagnostic pop } private: