From 4e741e91372eeb8a81eea19d1302f73bb09d37bd Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Wed, 7 Aug 2019 00:19:18 +0200 Subject: [PATCH] Synchronize warning flags between Xcode and Clang Signed-off-by: Jeroen Koekkoek --- CMakeLists.txt | 18 +++++++++++-- src/core/ddsc/tests/subscriber.c | 5 ++++ src/ddsrt/include/dds/ddsrt/misc.h | 42 +++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 012c247..4293a6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,9 +93,23 @@ endif() # Set reasonably strict warning options for clang, gcc, msvc # Enable coloured ouput if Ninja is used for building -if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") +if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") #message(STATUS clang) - add_compile_options(-Wall -Wextra -Wconversion -Wunused -Wmissing-prototypes) + set(wflags "-Wall" + "-Wextra" + "-Wconversion" + "-Wunused" + "-Wmissing-prototypes" + "-Winfinite-recursion" + "-Wassign-enum" + "-Wcomma" + "-Wmissing-prototypes" + "-Wdocumentation" + "-Wstrict-prototypes" + "-Wconditional-uninitialized" + "-Wshadow") + add_compile_options(${wflags}) if(${WERROR}) add_compile_options(-Werror) endif() diff --git a/src/core/ddsc/tests/subscriber.c b/src/core/ddsc/tests/subscriber.c index 02a8625..46696cb 100644 --- a/src/core/ddsc/tests/subscriber.c +++ b/src/core/ddsc/tests/subscriber.c @@ -10,6 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "dds/dds.h" +#include "dds/ddsrt/misc.h" #include #include "CUnit/Test.h" @@ -82,14 +83,18 @@ CU_Test(ddsc_subscriber, create) { dds_delete_qos(sqos); sqos = dds_create_qos(); + DDSRT_WARNING_CLANG_OFF(assign-enum); dds_qset_destination_order(sqos, 3); /* Set invalid dest. order (ignored, not applicable for subscriber) */ + DDSRT_WARNING_CLANG_ON(assign-enum); subscriber = dds_create_subscriber(participant, sqos, NULL); CU_ASSERT_FATAL(subscriber > 0); dds_delete(subscriber); dds_delete_qos(sqos); sqos = dds_create_qos(); + DDSRT_WARNING_CLANG_OFF(assign-enum); dds_qset_presentation(sqos, 123, 1, 1); /* Set invalid presentation policy */ + DDSRT_WARNING_CLANG_ON(assign-enum); subscriber = dds_create_subscriber(participant, sqos, NULL); CU_ASSERT_EQUAL_FATAL(subscriber, DDS_RETCODE_BAD_PARAMETER); dds_delete_qos(sqos); diff --git a/src/ddsrt/include/dds/ddsrt/misc.h b/src/ddsrt/include/dds/ddsrt/misc.h index edfbb24..582a52d 100644 --- a/src/ddsrt/include/dds/ddsrt/misc.h +++ b/src/ddsrt/include/dds/ddsrt/misc.h @@ -18,29 +18,45 @@ extern "C" { #endif -#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 -# define DDSRT_GNUC_STR(s) #s -# define DDSRT_GNUC_JOINSTR(x,y) DDSRT_GNUC_STR(x ## y) -# define DDSRT_GNUC_DO_PRAGMA(x) _Pragma (#x) -# define DDSRT_GNUC_PRAGMA(x) DDSRT_GNUC_DO_PRAGMA(GCC diagnostic x) -# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 +#if defined(__clang__) || \ + defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 +# define DDSRT_STR(s) #s +# define DDSRT_JOINSTR(x,y) DDSRT_STR(x ## y) +# define DDSRT_DO_PRAGMA(x) _Pragma(#x) +# define DDSRT_PRAGMA(x) DDSRT_DO_PRAGMA(GCC diagnostic x) + +# if defined(__clang__) +# define DDSRT_WARNING_CLANG_OFF(x) \ + DDSRT_PRAGMA(push) \ + DDSRT_PRAGMA(ignored DDSRT_JOINSTR(-W,x)) +# define DDSRT_WARNING_CLANG_ON(x) \ + DDSRT_PRAGMA(pop) +# elif ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 # define DDSRT_WARNING_GNUC_OFF(x) \ - DDSRT_GNUC_PRAGMA(push) \ - DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x)) + DDSRT_PRAGMA(push) \ + DDSRT_PRAGMA(ignored DDSRT_JOINSTR(-W,x)) # define DDSRT_WARNING_GNUC_ON(x) \ - DDSRT_GNUC_PRAGMA(pop) + DDSRT_PRAGMA(pop) # else # define DDSRT_WARNING_GNUC_OFF(x) \ - DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x)) + DDSRT_PRAGMA(ignored DDSRT_JOINSTR(-W,x)) # define DDSRT_WARNING_GNUC_ON(x) \ - DDSRT_GNUC_PRAGMA(warning DDSRT_GNUC_JOINSTR(-W,x)) + DDSRT_PRAGMA(warning DDSRT_JOINSTR(-W,x)) # endif -#else +#endif + +#if !defined(DDSRT_WARNING_CLANG_OFF) && \ + !defined(DDSRT_WARNING_CLANG_ON) +# define DDSRT_WARNING_CLANG_OFF(x) +# define DDSRT_WARNING_CLANG_ON(x) +#endif + +#if !defined(DDSRT_WARNING_GNUC_OFF) && \ + !defined(DDSRT_WARNING_GNUC_ON) # define DDSRT_WARNING_GNUC_OFF(x) # define DDSRT_WARNING_GNUC_ON(x) #endif - #if defined(_MSC_VER) # define DDSRT_WARNING_MSVC_OFF(x) \ __pragma (warning(push)) \