Cast qualifier warning on Windows LLVM clang 16 with CMake FetchContent
メンテナーはふだん 12 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- c, cmake
調査の方向性
cast_away_const() ヘルパーとその周囲の診断プラグマの付近にある cJSON.c を調査します。Windows 上で LLVM clang 16 を使用して報告された CMake FetchContent ビルドを再現し、その後、既存の cJSON の動作を変更せずに cast-qualifier 警告によってビルドが失敗しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- C
- スター
- 13k
- フォーク
- 3.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DaveGamble/cJSON のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1106 ·
メンテナーはふだん 12 日以内に返信
-
Undefined-Behavior in function cJSON_SetNumberHelper対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DaveGamble/cJSON#1100 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
DaveGamble/cJSON#1094 · コメント 9 件 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1093 ·
メンテナーはふだん 12 日以内に返信
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch array対応中かも @iliasabk が 29 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
DaveGamble/cJSON#1082 ·
メンテナーはふだん 12 日以内に返信
DaveGamble/cJSON の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
kubernetes-sigs/security-profiles-operator#3597 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
AFLplusplus/AFLplusplus#2903 ·
-
Clean up stale and inaccurate comments in the platform screen and input files対応中かも @RichStephens が今日担当しました。 オープン
難易度 2/5 半日 初心者へのやさしさ 88/100
FujiNetWIFI/fujinet-config#289 ·
メンテナーはふだん 1 日以内に返信
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
nasa/cFS-GroundSystem#272 ·