Cast qualifier warning on Windows LLVM clang 16 with CMake FetchContent
Maintainer thường phản hồi trong vòng 12 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- c, cmake
- Lĩnh vực
- build-system, compilers
Hướng nghiên cứu
Kiểm tra cJSON.c xung quanh helper cast_away_const() và các pragma chẩn đoán bao quanh nó. Tái hiện bản build CMake FetchContent đã được báo cáo bằng LLVM clang 16 trên Windows, sau đó xác minh rằng cảnh báo cast-qualifier không còn khiến bản build thất bại, đồng thời hành vi hiện có của cJSON vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi,
I'm compiling cJSON using CMake FetchContent with LLVM clang 16 on Windows:
> clang.exe --version
clang version 16.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\bin
This results in a compile warning because it seems to inherit the high warning levels of my parent project:
C:\LLVM\bin\clang.exe -DCJSON_API_VISIBILITY -DCJSON_EXPORT_SYMBOLS -DENABLE_LOCALES -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wundef -Wswitch-default -Wconversion -Wc++-compat -fstack-protector-strong -Wcomma -Wdouble-promotion -Wparentheses -Wunused-macros -Wmissing-variable-declarations -Wused-but-marked-unused -Wswitch-enum -fvisibility=hidden -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -MD -MT _deps/cjson-build/CMakeFiles/cjson.dir/cJSON.c.obj -MF _deps\cjson-build\CMakeFiles\cjson.dir\cJSON.c.obj.d -o _deps/cjson-build/CMakeFiles/cjson.dir/cJSON.c.obj -c C:/src/project/build/ninja/Debug/_deps/cjson-src/cJSON.c
C:/src/project/build/ninja/Debug/_deps/cjson-src/cJSON.c:2022:19: error: cast from 'const void *' to 'void *' drops const qualifier [-Werror,-Wcast-qual]
return (void*)string;
^
1 error generated.
I can of course suppress warnings in cJSON from my parent project, so this is a very minor issue, but if you'd like to address it anyway in the cJSON source, then either of the changes in the patch seems to work for me:
diff --git a/cJSON.c b/cJSON.c
index 61483d9..b3e4ac4 100644
--- a/cJSON.c
+++ b/cJSON.c
@@ -2012,14 +2012,12 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item)
#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic push
-#endif
-#ifdef __GNUC__
-#pragma GCC diagnostic ignored "-Wcast-qual"
+ #pragma GCC diagnostic ignored "-Wcast-qual"
#endif
/* helper function to cast away const */
static void* cast_away_const(const void* string)
{
- return (void*)string;
+ return (void*)(uintptr_t)string;
}
#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
#pragma GCC diagnostic pop
Evidently LLVM clang 16 does not define __GNUC__:
> C:\apps\LLVM\bin\clang.exe -dM -E -x c NUL | grep __G
#define __GCC_ASM_FLAG_OUTPUTS__ 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
So having different #ifdef blocks for the diagnostic sections around the cast_away_const() function isn't having the desired effect in this case, but it seems like it should be safe to combine them, which works since __clang__ is defined.
On the other hand, potentially you could get rid of the preprocessor wrappers around this function and just do an intermediate cast to uintptr_t as demonstrated in the above patch to avoid the cast qualifier warning.
Of course if you don't care to change this at all, that's fine too.
Thanks,
Benbuck
- Ngôn ngữ chính
- C
- Star
- 13k
- Fork
- 3.5k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DaveGamble/cJSON
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DaveGamble/cJSON#1106 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Undefined-Behavior in function cJSON_SetNumberHelperCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
DaveGamble/cJSON#1100 · 1 reaction ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
DaveGamble/cJSON#1094 · 9 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DaveGamble/cJSON#1093 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch arrayCó thể đã có người làm @iliasabk đã nhận 30 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
DaveGamble/cJSON#1082 ·
Maintainer thường phản hồi trong vòng 12 ngày
Tất cả issue của DaveGamble/cJSON
Issue tương tự
-
Missing options in yara man pageĐang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
VirusTotal/yara#2255 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
neutralinojs/neutralinojs#1861 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Filename sequence expansion (`+`) panics on numeric values exceeding `i32::MAX`Có thể đã có người làm @muntasir-396 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
CCExtractor/ccextractor#2402 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
FujiNetWIFI/fujinet-lib#204 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
os:linux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mpv-player/mpv#18649 ·
Maintainer thường phản hồi trong vòng 1 ngày