ibireme/yyjson

Improve compiler warnings handling

Closed this issue · 3 comments

When compiled via GCC 12 with -Wduplicated-branches, there's a warning:

val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \

yyjson.c:4122:50: error: this condition has identical branches [-Werror=duplicated-branches]
 4122 |     val->uni.u64 = (u64)(sign ? (u64)(~(_v) + 1) : (u64)(_v)); \
      |                                                  ^
yyjson.c:4170:32: note: in expansion of macro ‘return_i64’
 4170 |         if (!digi_is_fp(*cur)) return_i64(0);
      |                                ^~~~~~~~~~
compilation terminated due to -Wfatal-errors.

With -Wfloat-equal:

if (unlikely(val->uni.f64 == HUGE_VAL || val->uni.f64 == -HUGE_VAL)) {

yyjson.c:4251:31: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
 4251 |     if (unlikely(val->uni.f64 == HUGE_VAL || val->uni.f64 == -HUGE_VAL)) {
      |                               ^~
yyjson.c:4251:59: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
 4251 |     if (unlikely(val->uni.f64 == HUGE_VAL || val->uni.f64 == -HUGE_VAL)) {
      |                                                           ^~                                                

Clang issues warnings only for -Wfloat-equal.

I tried to copy yyjson.h and yyjson.c into my project sources, instead of compiling the library, so the compiler flags from my project issued these warnings.

It seems that the warning options in CMakeLists are not enough, I will add some more warning options and fix the corresponding warnings soon.

Fixed: 8b8df87