【发布时间】:2020-01-29 05:12:44
【问题描述】:
我正在使用以下文件尝试clang-tidy:
#include <stdio.h>
int main(int argc, char **argv)
{
int i=2; int j=1;
if (argc = 5) { return 2; }
while (i<argc) { j++; }
return 0;
}
我的目标是检测无限循环:
$ clang-tidy -checks=bugprone-infinite-loop main.c
但clang-tidy 找到的只是= 而不是== 的东西:
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "main.c"
No compilation database found in /home/oren or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 warning generated.
/home/oren/main.c:6:11: warning: using the result of an assignment as a condition without parentheses [clang-diagnostic-parentheses]
if (argc = 5) { return 2; }
~~~~ ^ ~
( == )
/home/oren/main.c:6:11: note: place parentheses around the assignment to silence this warning
/home/oren/main.c:6:11: note: use '==' to turn this assignment into an equality comparison
【问题讨论】:
-
我最初认为错误是因为 if 导致的,这使得循环无法访问,但我的 clang tidy 版本也无法找到 if 已修复的问题。
标签: llvm anti-patterns clang-tidy