From e69db83de5533e9817195ca82b7c0d178d0d3ab2 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 8 Dec 2016 13:21:18 +0100 Subject: [PATCH 1/2] Temporarily disable warning when const is cast away. There was a long running discussion here https://github.com/DaveGamble/cJSON/pull/80 how to provide const correctness for users of cJSON. To avoid breaking changes for users of cJSON v1 it was decided to disable this warning. pragma was tested with gcc 5.4.0/6.2.1 and clang 3.8/3.9. --- cJSON.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cJSON.c b/cJSON.c index bba72d8..a409c8d 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1756,7 +1756,10 @@ void cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { cJSON_free(item->string); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" item->string = (char*)string; +#pragma GCC diagnostic pop item->type |= cJSON_StringIsConst; cJSON_AddItemToArray(object, item); } From 89edfb6741a13181bc11ff7666b7658af050e93c Mon Sep 17 00:00:00 2001 From: Stephan Gatzka Date: Wed, 7 Dec 2016 12:50:00 +0100 Subject: [PATCH 2/2] Warn if cast removes a type qualifier like const. --- CMakeLists.txt | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6deeecf..61294bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON) if (ENABLE_CUSTOM_COMPILER_FLAGS) if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual") endif() endif() diff --git a/Makefile b/Makefile index c56618c..8c76794 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) INSTALL ?= cp -a -R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 $(CFLAGS) +R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual $(CFLAGS) uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')