From 7b3637417062fe657c0bf1fced5ef59a489dbdc3 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Mon, 9 Mar 2020 10:04:24 +0000 Subject: [PATCH] Adjust some warnings Remove -Werror and add -fpermissive, this will allow to compile C code with a GNU C++ compiler. Ignore warnings as our code use some feature like empty arrays. Remove warnings not available in C++. Bump GLIB_VERSION_MAX_ALLOWED to reduce the warning, looks like the GLib headers for C++ are not able to handle them correctly. Signed-off-by: Frediano Ziglio --- configure.ac | 5 ++++- m4/spice-compile-warnings.m4 | 43 +++++++++++++++++++++++++++++++++++- meson.build | 12 ++++++++++ server/red-client.c | 2 +- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 281fc826..dddb5783 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AC_PROG_CXX AC_LANG_PUSH([C++]) m4_ifndef([AX_CXX_COMPILE_STDCXX_11], [m4_fatal([Missing AX_CXX_COMPILE_STDCXX_11, install autoconf-archive])]) AX_CXX_COMPILE_STDCXX_11 +AX_APPEND_COMPILE_FLAGS([-fno-exceptions -fno-rtti -fno-check-new --no_rtti]) AC_LANG_POP([C++]) AC_CHECK_HEADERS([sys/time.h execinfo.h linux/sockios.h pthread_np.h]) @@ -187,7 +188,7 @@ GLIB2_REQUIRED=2.38 GLIB2_ENCODED_VERSION="GLIB_VERSION_2_38" PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= $GLIB2_REQUIRED gio-2.0 >= $GLIB2_REQUIRED]) GLIB2_CFLAGS="$GLIB2_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=$GLIB2_ENCODED_VERSION \ - -DGLIB_VERSION_MAX_ALLOWED=$GLIB2_ENCODED_VERSION" + -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_60" AS_VAR_APPEND([SPICE_REQUIRES], [" glib-2.0 >= $GLIB2_REQUIRED gio-2.0 >= $GLIB2_REQUIRED"]) PKG_CHECK_MODULES([GOBJECT2], [gobject-2.0 >= $GLIB2_REQUIRED]) @@ -262,7 +263,9 @@ AS_IF([test "$enable_statistics" = "yes"], dnl =========================================================================== dnl check compiler flags +AC_LANG_PUSH([C++]) SPICE_COMPILE_WARNINGS +AC_LANG_POP([C++]) LIBVIRT_LINKER_RELRO LIBVIRT_LINKER_NO_INDIRECT diff --git a/m4/spice-compile-warnings.m4 b/m4/spice-compile-warnings.m4 index 2081475e..2b753b0e 100644 --- a/m4/spice-compile-warnings.m4 +++ b/m4/spice-compile-warnings.m4 @@ -68,6 +68,28 @@ AC_DEFUN([SPICE_COMPILE_WARNINGS],[ # decl mess with gtk/generated_*.c dontwarn="$dontwarn -Wmissing-declarations" + # Stuff that C++ won't allow. Turn them back on later + dontwarn="$dontwarn -Wdesignated-init" + dontwarn="$dontwarn -Wdiscarded-array-qualifiers" + dontwarn="$dontwarn -Wdiscarded-qualifiers" + dontwarn="$dontwarn -Wimplicit" + dontwarn="$dontwarn -Wimplicit-function-declaration" + dontwarn="$dontwarn -Wimplicit-int" + dontwarn="$dontwarn -Wincompatible-pointer-types" + dontwarn="$dontwarn -Wint-conversion" + dontwarn="$dontwarn -Wjump-misses-init" + dontwarn="$dontwarn -Wmissing-parameter-type" + dontwarn="$dontwarn -Wmissing-prototypes" + dontwarn="$dontwarn -Wnested-externs" + dontwarn="$dontwarn -Wold-style-declaration" + dontwarn="$dontwarn -Wold-style-definition" + dontwarn="$dontwarn -Woverride-init" + dontwarn="$dontwarn -Wpointer-sign" + dontwarn="$dontwarn -Wpointer-to-int-cast" + dontwarn="$dontwarn -Wstrict-prototypes" + dontwarn="$dontwarn -Wsuggest-final-methods" + dontwarn="$dontwarn -Wsuggest-final-types" + # Get all possible GCC warnings gl_MANYWARN_ALL_GCC([maybewarn]) @@ -131,9 +153,28 @@ AC_DEFUN([SPICE_COMPILE_WARNINGS],[ then gl_WARN_ADD([-Werror]) fi - WARN_CXXFLAGS=$WARN_CFLAGS + + save_CFLAGS="$WARN_CFLAGS" + + # -fpermissive to allow compile C with C++ + gl_WARN_ADD([-fpermissive]) + + # -Wno-suggest-final-methods and -Wno-suggest-final-types to avoid warnings for optimization + gl_WARN_ADD([-Wno-suggest-final-methods]) + gl_WARN_ADD([-Wno-suggest-final-types]) + + # -Wno-array-bounds to avoid checks for array with 0 size + gl_WARN_ADD([-Wno-array-bounds]) + + # -Wno-narrowing to allow cast from -1 to unsigned (used in some initialization) + gl_WARN_ADD([-Wno-narrowing]) + + gl_WARN_ADD([-Wno-missing-field-initializers]) + + WARN_CXXFLAGS="$WARN_CFLAGS" AC_SUBST([WARN_CXXFLAGS]) + WARN_CFLAGS="$save_CFLAGS" WARN_LDFLAGS=$WARN_CFLAGS AC_SUBST([WARN_CFLAGS]) AC_SUBST([WARN_LDFLAGS]) diff --git a/meson.build b/meson.build index 710606e2..77dcdf08 100644 --- a/meson.build +++ b/meson.build @@ -191,6 +191,18 @@ add_project_arguments(compiler.get_supported_arguments(spice_server_global_cflag language : 'c') spice_server_global_cxxflags = spice_server_global_cflags +spice_server_global_cxxflags += [ + '-fno-exceptions', + '-fno-rtti', + '--no_rtti', + '-fpermissive', + '-Wno-suggest-final-methods', + '-Wno-suggest-final-types', + '-Wno-array-bounds', + '-Wno-narrowing', + '-Wno-missing-field-initializers', + '-Wno-deprecated-declarations', +] add_project_arguments(cxx_compiler.get_supported_arguments(spice_server_global_cxxflags), language : 'cpp') diff --git a/server/red-client.c b/server/red-client.c index b187a039..469c144c 100644 --- a/server/red-client.c +++ b/server/red-client.c @@ -293,7 +293,7 @@ gboolean red_client_add_channel(RedClient *client, RedChannelClient *rcc, GError // first must be the main one if (!client->mcc) { - client->mcc = g_object_ref(rcc); + client->mcc = (MainChannelClient *) g_object_ref(rcc); spice_assert(MAIN_CHANNEL_CLIENT(rcc) != NULL); } client->channels = g_list_prepend(client->channels, rcc);