Synchronize warning flags between Xcode and Clang

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-08-07 00:19:18 +02:00 committed by eboasson
parent 1200bfd109
commit 4e741e9137
3 changed files with 50 additions and 15 deletions

View file

@ -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()

View file

@ -10,6 +10,7 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include "dds/dds.h"
#include "dds/ddsrt/misc.h"
#include <stdio.h>
#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);

View file

@ -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)) \