clang-tidy无法通过易错检查

问题描述 投票:1回答:1

我正在使用以下文件来尝试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

llvm anti-patterns clang-tidy
1个回答
0
投票

您正在使用尚未发布的LLVM(10.0.0)版本中的功能。

在我的系统上(Windows),您的文件可以正常工作:

© www.soinside.com 2019 - 2024. All rights reserved.