From 4386814b045a74c10edad5effafd48ac869ebda1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 30 Jan 2019 02:01:50 +0100 Subject: build: set compiler options in one place - add_definitions() is preferred to CMAKE_C_FLAGS. --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0629403dfe..213709cb8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,11 +172,6 @@ if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG) string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") endif() -# Enable -Wconversion. -if(NOT MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wconversion") -endif() - # gcc 4.0+ sets _FORTIFY_SOURCE=2 automatically. This currently # does not work with Neovim due to some uses of dynamically-sized structures. # https://github.com/neovim/neovim/issues/223 @@ -264,7 +259,7 @@ if(MSVC) add_definitions(-DWIN32) else() add_definitions(-Wall -Wextra -pedantic -Wno-unused-parameter - -Wstrict-prototypes -std=gnu99) + -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion) check_c_compiler_flag(-Wimplicit-fallthrough HAS_WIMPLICIT_FALLTHROUGH_FLAG) if(HAS_WIMPLICIT_FALLTHROUGH_FLAG) -- cgit From f2c6164b04709b83b60483642ed9b6f33cf01951 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 30 Jan 2019 02:26:12 +0100 Subject: build: -Wmissing-prototypes ref #343 Though I don't see a strong benefit, it isn't too much of a burden, and maybe avoids confusion in some cases. --- CMakeLists.txt | 3 ++- src/nvim/aucmd.c | 1 + src/nvim/eval.c | 4 ++++ src/nvim/eval/decode.c | 1 + src/nvim/generators/gen_api_dispatch.lua | 1 + src/nvim/main.c | 1 + src/nvim/os/dl.c | 1 + src/nvim/os/lang.c | 1 + test/functional/fixtures/tty-test.c | 1 + 9 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 213709cb8e..d3ea80c926 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,7 +259,8 @@ if(MSVC) add_definitions(-DWIN32) else() add_definitions(-Wall -Wextra -pedantic -Wno-unused-parameter - -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion) + -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion + -Wmissing-prototypes) check_c_compiler_flag(-Wimplicit-fallthrough HAS_WIMPLICIT_FALLTHROUGH_FLAG) if(HAS_WIMPLICIT_FALLTHROUGH_FLAG) diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index 9ad3414b79..3bb0fcec3b 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -6,6 +6,7 @@ #include "nvim/vim.h" #include "nvim/main.h" #include "nvim/ui.h" +#include "nvim/aucmd.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "aucmd.c.generated.h" diff --git a/src/nvim/eval.c b/src/nvim/eval.c index df02a5ba17..8ca764ba68 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5958,6 +5958,10 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) #pragma function (floor) #endif +// silence -Wmissing-prototypes for funcs.generated.h +const VimLFuncDef *find_internal_func_gperf(register const char *str, + register size_t len); + # include "funcs.generated.h" #endif diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 4d75c7bda1..42999ddd62 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -7,6 +7,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval.h" +#include "nvim/eval/decode.h" #include "nvim/eval/encode.h" #include "nvim/ascii.h" #include "nvim/macros.h" diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua index bd9650e4d1..3703b76973 100644 --- a/src/nvim/generators/gen_api_dispatch.lua +++ b/src/nvim/generators/gen_api_dispatch.lua @@ -448,6 +448,7 @@ for _, fn in ipairs(functions) do end output:write(string.format([[ +void nlua_add_api_functions(lua_State *lstate); // silence -Wmissing-prototypes void nlua_add_api_functions(lua_State *lstate) FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/main.c b/src/nvim/main.c index 9c8711495c..5d67f53ec4 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -222,6 +222,7 @@ void early_init(void) } #ifdef MAKE_LIB +int nvim_main(int argc, char **argv); // silence -Wmissing-prototypes int nvim_main(int argc, char **argv) #elif defined(WIN32) int wmain(int argc, wchar_t **argv_w) // multibyte args on Windows. #7060 diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c index 267cf5ae4b..bbd0424a82 100644 --- a/src/nvim/os/dl.c +++ b/src/nvim/os/dl.c @@ -7,6 +7,7 @@ #include #include +#include "nvim/os/dl.h" #include "nvim/os/os.h" #include "nvim/memory.h" #include "nvim/message.h" diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 108a9c6c39..fe2d7986bf 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -11,6 +11,7 @@ #ifdef HAVE_LOCALE_H # include #endif +#include "nvim/os/lang.h" #include "nvim/os/os.h" void lang_init(void) diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 5f1f5cb91c..e2a78a594b 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -20,6 +20,7 @@ uv_tty_t tty; uv_tty_t tty_out; +bool owns_tty(void); // silence -Wmissing-prototypes bool owns_tty(void) { #ifdef _WIN32 -- cgit From 45f25f7e0b3f105faebf5e215e5c128346463046 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 4 Feb 2019 03:43:38 +0100 Subject: build: PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES On Travis CI, -Wmissing-prototypes gives strange error: In file included from ../src/nvim/eval.c:5965: /home/travis/build/neovim/neovim/build/src/nvim/auto/funcs.generated.h.gperf:215:1: error: conflicting types for 'find_internal_func_gperf' find_internal_func_gperf (register const char *str, register unsigned int len) ^ ../src/nvim/eval.c:5962:20: note: previous declaration is here const VimLFuncDef *find_internal_func_gperf(register const char *str, ^ --- src/nvim/assert.h | 6 +++--- src/nvim/eval.c | 6 ++---- src/nvim/macros.h | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 6e8e57c183..34734f294d 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -80,7 +80,7 @@ # undef STATIC_ASSERT_PRAGMA_END # define STATIC_ASSERT_PRAGMA_END \ - _Pragma("GCC diagnostic pop") \ + _Pragma("GCC diagnostic pop") // the same goes for clang in C99 mode, but we suppress a different warning #elif defined(__clang__) && __has_extension(c_static_assert) @@ -90,11 +90,11 @@ # undef STATIC_ASSERT_PRAGMA_START # define STATIC_ASSERT_PRAGMA_START \ _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc11-extensions\"") # undef STATIC_ASSERT_PRAGMA_END # define STATIC_ASSERT_PRAGMA_END \ - _Pragma("clang diagnostic pop") \ + _Pragma("clang diagnostic pop") // TODO(aktau): verify that this works, don't have MSVC on hand. #elif _MSC_VER >= 1600 diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8ca764ba68..4ab699cdb7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5958,11 +5958,9 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) #pragma function (floor) #endif -// silence -Wmissing-prototypes for funcs.generated.h -const VimLFuncDef *find_internal_func_gperf(register const char *str, - register size_t len); - +PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES # include "funcs.generated.h" +PRAGMA_DIAG_POP #endif /* diff --git a/src/nvim/macros.h b/src/nvim/macros.h index d447bff765..61009528a8 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -198,4 +198,25 @@ # define IO_COUNT(x) (x) #endif +/// +/// PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES +/// +#if defined(__clang__) && __clang__ == 1 +# define PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wmissing-prototypes\"") +# define PRAGMA_DIAG_POP \ + _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +# define PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"") +# define PRAGMA_DIAG_POP \ + _Pragma("GCC diagnostic pop") +#else +# define PRAGMA_DIAG_PUSH_IGNORE_MISSING_PROTOTYPES +# define PRAGMA_DIAG_POP +#endif + + #endif // NVIM_MACROS_H -- cgit