【发布时间】:2021-05-15 18:57:06
【问题描述】:
比如我有这个sn-p:
const int array_type = model.accessors[accessor_index].type;
Assert(array_type == TypeCode<T>(), "");
我得到这个错误:
Src/Engine/Animation/GltfLib.cpp:103:26: style: Variable 'array_type' is assigned a value that is never used. [unreadVariable]
const int array_type = model.accessors[accessor_index].type;
Assert 是一个基于常规 assert 的宏,但在引发错误的基础上使用了一些内部日志记录机制。
有没有办法让 cppcheck 注意到变量被实际使用了?
【问题讨论】:
-
如果
Assert宏是基于标准库的assert宏,那么这段代码确实可以不使用array_type。当assert被禁用时会发生这种情况。 -
为了让 cppcheck 满意,我需要让代码仅在启用 Assert 时可用?
-
对于标准库的
assert宏,使用model.accessors[accessor_index].type == TypeCode<T>()并删除array_type可能会消除警告。
标签: c++ macros static-analysis cppcheck