AC6编译cstring.c和ctime.c产生编译警告comparison of nonnull parameter
KEIL5 AC6编译器 编译cstring.c和ctime.c产生编译警告
compilers/common/cstring.c(194): error: nonnull parameter 'saveptr' will evaluate to 'true' on first encounter [-Werror,-Wpointer-bool-conversion] else if (saveptr && *saveptr) ^~~~~~~ ~~
ctime.c(255): error: comparison of nonnull parameter 't' equal to a null pointer is 'false' on first encounter [-Werror,-Wtautological-pointer-compare] if(t == RT_NULL || buf == RT_NULL) ^ ~~~~~~~
- 警告具体含义如下:
https://clang.llvm.org/docs/DiagnosticsReference.html#wpointer-bool-conversion
https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-pointer-compare
- 警告具体位置如下:

- Build Output如下
Build started: Project: project
*** Using Compiler 'V6.18', folder: 'D:\Program Files(x86)\Keil\Keil_v5\ARM\ARMCLANG\Bin'
Build target 'rt-thread'
rt-thread/components/libc/compilers/common/cstring.c(194): error: nonnull parameter 'saveptr' will evaluate to 'true' on first encounter [-Werror,-Wpointer-bool-conversion]
else if (saveptr && *saveptr)
^~~~~~~ ~~
D:\Program Files(x86)\Keil\Keil_v5\ARM\ARMCLANG\Bin\..\include\string.h(283): note: declared 'nonnull' here
extern _ARMABI char *strtok_r(char * /*s1*/, const char * /*s2*/, char ** /*ptr*/) __attribute__((__nonnull__(2,3)));
^
rt-thread/components/libc/compilers/common/cstring.c(217): error: nonnull parameter 'saveptr' will evaluate to 'true' on first encounter [-Werror,-Wpointer-bool-conversion]
if (saveptr)
~~ ^~~~~~~
D:\Program Files(x86)\Keil\Keil_v5\ARM\ARMCLANG\Bin\..\include\string.h(283): note: declared 'nonnull' here
extern _ARMABI char *strtok_r(char * /*s1*/, const char * /*s2*/, char ** /*ptr*/) __attribute__((__nonnull__(2,3)));
^
2 errors generated.
compiling cstring.c...
rt-thread/components/libc/compilers/common/ctime.c(255): error: comparison of nonnull parameter 't' equal to a null pointer is 'false' on first encounter [-Werror,-Wtautological-pointer-compare]
if(t == RT_NULL || buf == RT_NULL)
^ ~~~~~~~
D:\Program Files(x86)\Keil\Keil_v5\ARM\ARMCLANG\Bin\..\include\time.h(171): note: declared 'nonnull' here
char * __restrict /*buf*/) __attribute__((__nonnull__(1,2)));
^
rt-thread/components/libc/compilers/common/ctime.c(255): error: comparison of nonnull parameter 'buf' equal to a null pointer is 'false' on first encounter [-Werror,-Wtautological-pointer-compare]
if(t == RT_NULL || buf == RT_NULL)
^~~ ~~~~~~~
D:\Program Files(x86)\Keil\Keil_v5\ARM\ARMCLANG\Bin\..\include\time.h(171): note: declared 'nonnull' here
char * __restrict /*buf*/) __attribute__((__nonnull__(1,2)));
^
2 errors generated.
compiling ctime.c...
".\build\keil\Obj\rt-thread.axf" - 4 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:01
使用 -Wno-pointer-bool-conversion -Wno-tautological-pointer-compare可取消警告

emmm 虽然使用-Wxxx可以干掉警告,但是有些自欺欺人,我想想怎么处理
emmm 虽然使用-Wxxx可以干掉警告,但是有些自欺欺人,我想想怎么处理
^_^,就是想不到怎么消除才提的。
报这个错误感觉有些和以前的认知不同。if (saveptr && *saveptr) 按理说没问题,非null的saveptr参数,第一次为True,这个时候可以/需要检查第二次的条件。这个是不是报错太多了?
这个问题先不处理,等smart完全合并之后统一处理,现在我也有一些问题攒着没有处理呢
测试没问题:stm32f103-atk-nano,AC6.15
https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-pointer-compare
