diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-11-02 15:13:06 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-11-06 01:32:10 +0000 |
commit | cf94537266a97a7f5309fdb2c566b2ac4860fa9a (patch) | |
tree | 398bcf60bad4ed99cb322ce826883370e0892669 | |
parent | ee3121c3f6025562972c167d4db2e8ed38860479 (diff) |
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.
-rw-r--r-- | CMakeLists.txt | 100 | ||||
-rw-r--r-- | auto_tests/tox_test.c | 2 | ||||
-rw-r--r-- | cmake/ModulePackage.cmake | 9 | ||||
-rw-r--r-- | testing/nTox.c | 2 |
4 files changed, 99 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ec2b242..1585b8dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -20,20 +20,104 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | |||
20 | 20 | ||
21 | include(ApiDsl) | 21 | include(ApiDsl) |
22 | include(CheckCCompilerFlag) | 22 | include(CheckCCompilerFlag) |
23 | include(CheckCXXCompilerFlag) | ||
23 | include(MacRpath) | 24 | include(MacRpath) |
24 | include(ModulePackage) | 25 | include(ModulePackage) |
25 | 26 | ||
26 | set(CMAKE_MACOSX_RPATH ON) | 27 | set(CMAKE_MACOSX_RPATH ON) |
27 | 28 | ||
29 | function(add_cflag flag) | ||
30 | string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag}) | ||
31 | if(NOT DEFINED HAVE_C${var}) | ||
32 | message(STATUS "checking for C compiler flag: ${flag}") | ||
33 | endif() | ||
34 | set(CMAKE_REQUIRED_QUIET TRUE) | ||
35 | |||
36 | check_c_compiler_flag("${flag}" HAVE_C${var} QUIET) | ||
37 | if(HAVE_C${var}) | ||
38 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) | ||
39 | endif() | ||
40 | endfunction() | ||
41 | |||
42 | function(add_cxxflag flag) | ||
43 | string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" var ${flag}) | ||
44 | if(NOT DEFINED HAVE_CXX${var}) | ||
45 | message(STATUS "checking for C++ compiler flag: ${flag}") | ||
46 | endif() | ||
47 | set(CMAKE_REQUIRED_QUIET TRUE) | ||
48 | |||
49 | check_cxx_compiler_flag("${flag}" HAVE_CXX${var} QUIET) | ||
50 | if(HAVE_CXX${var}) | ||
51 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) | ||
52 | endif() | ||
53 | endfunction() | ||
54 | |||
55 | macro(add_flag flag) | ||
56 | add_cflag(${flag}) | ||
57 | add_cxxflag(${flag}) | ||
58 | endmacro() | ||
59 | |||
60 | option(WARNINGS "Enable additional compiler warnings" ON) | ||
61 | if(WARNINGS) | ||
62 | # Set standard version for compiler. | ||
63 | add_cflag("-std=gnu99") | ||
64 | add_cxxflag("-std=c++98") | ||
65 | |||
66 | # Add all warning flags we can. | ||
67 | add_flag("-Wall") | ||
68 | add_flag("-Wextra") | ||
69 | add_flag("-Weverything") | ||
70 | add_flag("-pedantic") | ||
71 | |||
72 | # Set error-on-warn for C compilation. C++ compilation can't use this because | ||
73 | # treating 'c' input as 'c++' when in C++ mode is deprecated in clang and | ||
74 | # there is no way to turn that warning off. | ||
75 | add_cflag("-Werror") | ||
76 | |||
77 | # Disable specific warning flags for both C and C++. | ||
78 | add_flag("-Wno-cast-align") | ||
79 | add_flag("-Wno-conversion") | ||
80 | add_flag("-Wno-covered-switch-default") | ||
81 | add_flag("-Wno-format-nonliteral") | ||
82 | add_flag("-Wno-missing-field-initializers") | ||
83 | add_flag("-Wno-missing-prototypes") | ||
84 | add_flag("-Wno-padded") | ||
85 | add_flag("-Wno-sign-compare") | ||
86 | add_flag("-Wno-sign-conversion") | ||
87 | add_flag("-Wno-tautological-constant-out-of-range-compare") | ||
88 | add_flag("-Wno-undef") | ||
89 | add_flag("-Wno-unreachable-code") | ||
90 | add_flag("-Wno-unused-macros") | ||
91 | add_flag("-Wno-unused-parameter") | ||
92 | add_flag("-Wno-vla") | ||
93 | |||
94 | # Disable specific warning flags for C. | ||
95 | add_cflag("-Wno-assign-enum") | ||
96 | add_cflag("-Wno-bad-function-cast") | ||
97 | add_cflag("-Wno-double-promotion") | ||
98 | add_cflag("-Wno-gnu-zero-variadic-macro-arguments") | ||
99 | add_cflag("-Wno-packed") | ||
100 | add_cflag("-Wno-reserved-id-macro") | ||
101 | add_cflag("-Wno-shadow") | ||
102 | add_cflag("-Wno-shorten-64-to-32") | ||
103 | add_cflag("-Wno-unreachable-code-return") | ||
104 | add_cflag("-Wno-used-but-marked-unused") | ||
105 | |||
106 | # Disable specific warning flags for C++. | ||
107 | add_cxxflag("-Wno-c++11-compat-reserved-user-defined-literal") | ||
108 | add_cxxflag("-Wno-c++11-extensions") | ||
109 | add_cxxflag("-Wno-c++11-narrowing") | ||
110 | add_cxxflag("-Wno-c99-extensions") | ||
111 | add_cxxflag("-Wno-old-style-cast") | ||
112 | add_cxxflag("-Wno-variadic-macros") | ||
113 | add_cxxflag("-Wno-vla-extension") | ||
114 | endif() | ||
115 | |||
28 | option(DEBUG "Enable assertions and other debugging facilities" OFF) | 116 | option(DEBUG "Enable assertions and other debugging facilities" OFF) |
29 | if(DEBUG) | 117 | if(DEBUG) |
30 | set(MIN_LOGGER_LEVEL DEBUG) | 118 | set(MIN_LOGGER_LEVEL DEBUG) |
31 | add_definitions(-DTOX_DEBUG=1) | 119 | add_definitions(-DTOX_DEBUG=1) |
32 | check_c_compiler_flag("-g3" HAVE_G3) | 120 | add_cflag("-g3") |
33 | if(HAVE_G3) | ||
34 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3") | ||
35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") | ||
36 | endif() | ||
37 | endif() | 121 | endif() |
38 | 122 | ||
39 | option(TRACE "Enable TRACE level logging (expensive, for network debugging)" OFF) | 123 | 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) | |||
54 | if(ASAN) | 138 | if(ASAN) |
55 | set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") | 139 | set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") |
56 | set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address") | 140 | set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address") |
57 | check_c_compiler_flag("-fsanitize=address" HAVE_ASAN) | 141 | add_cflag("-fsanitize=address") |
58 | if(HAVE_ASAN) | ||
59 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") | ||
60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") | ||
61 | endif() | ||
62 | set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") | 142 | set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") |
63 | endif() | 143 | endif() |
64 | 144 | ||
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 2706e564..1bcb8d5e 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -321,7 +321,7 @@ static void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, vo | |||
321 | 321 | ||
322 | START_TEST(test_few_clients) | 322 | START_TEST(test_few_clients) |
323 | { | 323 | { |
324 | long long unsigned int con_time, cur_time = time(NULL); | 324 | long long unsigned int con_time = 0, cur_time = time(NULL); |
325 | TOX_ERR_NEW t_n_error; | 325 | TOX_ERR_NEW t_n_error; |
326 | Tox *tox1 = tox_new(0, &t_n_error); | 326 | Tox *tox1 = tox_new(0, &t_n_error); |
327 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); | 327 | ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); |
diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake index a556aef0..26c6c39a 100644 --- a/cmake/ModulePackage.cmake +++ b/cmake/ModulePackage.cmake | |||
@@ -31,8 +31,13 @@ function(pkg_use_module mod) | |||
31 | if(${mod}_FOUND) | 31 | if(${mod}_FOUND) |
32 | link_directories(${${mod}_LIBRARY_DIRS}) | 32 | link_directories(${${mod}_LIBRARY_DIRS}) |
33 | include_directories(${${mod}_INCLUDE_DIRS}) | 33 | include_directories(${${mod}_INCLUDE_DIRS}) |
34 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}") | 34 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) |
35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}") | 35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}" PARENT_SCOPE) |
36 | |||
37 | foreach(dir ${${mod}_INCLUDE_DIRS}) | ||
38 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem ${dir}" PARENT_SCOPE) | ||
39 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${dir}" PARENT_SCOPE) | ||
40 | endforeach() | ||
36 | endif() | 41 | endif() |
37 | endfunction() | 42 | endfunction() |
38 | 43 | ||
diff --git a/testing/nTox.c b/testing/nTox.c index 3b24d903..88a80dac 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -184,7 +184,7 @@ static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
184 | 184 | ||
185 | static void fraddr_to_str(uint8_t *id_bin, char *id_str) | 185 | static void fraddr_to_str(uint8_t *id_bin, char *id_str) |
186 | { | 186 | { |
187 | uint32_t i, delta = 0, pos_extra, sum_extra = 0; | 187 | uint32_t i, delta = 0, pos_extra = 0, sum_extra = 0; |
188 | 188 | ||
189 | for (i = 0; i < TOX_ADDRESS_SIZE; i++) { | 189 | for (i = 0; i < TOX_ADDRESS_SIZE; i++) { |
190 | sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]); | 190 | sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]); |