Enable all possible C compiler warning flags.

We disable the ones that fire, so we can use -Werror. We can then
investigate each warning individually and see whether to fix it or to
keep silencing it.
This commit is contained in:
iphydf 2016-11-02 15:13:06 +00:00
parent ee3121c3f6
commit cf94537266
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
4 changed files with 99 additions and 14 deletions

View File

@ -20,20 +20,104 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(ApiDsl)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(MacRpath)
include(ModulePackage)
set(CMAKE_MACOSX_RPATH ON)
function(add_cflag flag)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag})
if(NOT DEFINED HAVE_C${var})
message(STATUS "checking for C compiler flag: ${flag}")
endif()
set(CMAKE_REQUIRED_QUIET TRUE)
check_c_compiler_flag("${flag}" HAVE_C${var} QUIET)
if(HAVE_C${var})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
function(add_cxxflag flag)
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag})
if(NOT DEFINED HAVE_CXX${var})
message(STATUS "checking for C++ compiler flag: ${flag}")
endif()
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("${flag}" HAVE_CXX${var} QUIET)
if(HAVE_CXX${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
macro(add_flag flag)
add_cflag(${flag})
add_cxxflag(${flag})
endmacro()
option(WARNINGS "Enable additional compiler warnings" ON)
if(WARNINGS)
# Set standard version for compiler.
add_cflag("-std=gnu99")
add_cxxflag("-std=c++98")
# Add all warning flags we can.
add_flag("-Wall")
add_flag("-Wextra")
add_flag("-Weverything")
add_flag("-pedantic")
# Set error-on-warn for C compilation. C++ compilation can't use this because
# treating 'c' input as 'c++' when in C++ mode is deprecated in clang and
# there is no way to turn that warning off.
add_cflag("-Werror")
# Disable specific warning flags for both C and C++.
add_flag("-Wno-cast-align")
add_flag("-Wno-conversion")
add_flag("-Wno-covered-switch-default")
add_flag("-Wno-format-nonliteral")
add_flag("-Wno-missing-field-initializers")
add_flag("-Wno-missing-prototypes")
add_flag("-Wno-padded")
add_flag("-Wno-sign-compare")
add_flag("-Wno-sign-conversion")
add_flag("-Wno-tautological-constant-out-of-range-compare")
add_flag("-Wno-undef")
add_flag("-Wno-unreachable-code")
add_flag("-Wno-unused-macros")
add_flag("-Wno-unused-parameter")
add_flag("-Wno-vla")
# Disable specific warning flags for C.
add_cflag("-Wno-assign-enum")
add_cflag("-Wno-bad-function-cast")
add_cflag("-Wno-double-promotion")
add_cflag("-Wno-gnu-zero-variadic-macro-arguments")
add_cflag("-Wno-packed")
add_cflag("-Wno-reserved-id-macro")
add_cflag("-Wno-shadow")
add_cflag("-Wno-shorten-64-to-32")
add_cflag("-Wno-unreachable-code-return")
add_cflag("-Wno-used-but-marked-unused")
# Disable specific warning flags for C++.
add_cxxflag("-Wno-c++11-compat-reserved-user-defined-literal")
add_cxxflag("-Wno-c++11-extensions")
add_cxxflag("-Wno-c++11-narrowing")
add_cxxflag("-Wno-c99-extensions")
add_cxxflag("-Wno-old-style-cast")
add_cxxflag("-Wno-variadic-macros")
add_cxxflag("-Wno-vla-extension")
endif()
option(DEBUG "Enable assertions and other debugging facilities" OFF)
if(DEBUG)
set(MIN_LOGGER_LEVEL DEBUG)
add_definitions(-DTOX_DEBUG=1)
check_c_compiler_flag("-g3" HAVE_G3)
if(HAVE_G3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
endif()
add_cflag("-g3")
endif()
option(TRACE "Enable TRACE level logging (expensive, for network debugging)" OFF)
@ -54,11 +138,7 @@ option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF)
if(ASAN)
set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
check_c_compiler_flag("-fsanitize=address" HAVE_ASAN)
if(HAVE_ASAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
add_cflag("-fsanitize=address")
set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")
endif()

View File

@ -321,7 +321,7 @@ static void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, vo
START_TEST(test_few_clients)
{
long long unsigned int con_time, cur_time = time(NULL);
long long unsigned int con_time = 0, cur_time = time(NULL);
TOX_ERR_NEW t_n_error;
Tox *tox1 = tox_new(0, &t_n_error);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");

View File

@ -31,8 +31,13 @@ function(pkg_use_module mod)
if(${mod}_FOUND)
link_directories(${${mod}_LIBRARY_DIRS})
include_directories(${${mod}_INCLUDE_DIRS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE)
foreach(dir ${${mod}_INCLUDE_DIRS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE)
endforeach()
endif()
endfunction()

View File

@ -184,7 +184,7 @@ static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename)
static void fraddr_to_str(uint8_t *id_bin, char *id_str)
{
uint32_t i, delta = 0, pos_extra, sum_extra = 0;
uint32_t i, delta = 0, pos_extra = 0, sum_extra = 0;
for (i = 0; i < TOX_ADDRESS_SIZE; i++) {
sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]);