gpt4 book ai didi

c++ - clang 的扫描构建不适用于简单的 cpp 文件

转载 作者:可可西里 更新时间:2023-11-01 17:52:09 26 4
gpt4 key购买 nike

我无法让 clang 的 c++-analyzer 处理玩具 C++ 文件。

#include <iostream>

using namespace std;

int main()
{
int t[4];
int x,y;

t[5]=1;
if(x)
y = 5;
x = t[y];
}

makefile 就是

all: t.cpp
$(CXX) t.cpp

scan-build make 输出:

scan-build: 'clang' executable not found in '/usr/share/clang/scan-build/bin'.
scan-build: Using 'clang' from path: /usr/bin/clang
/usr/share/clang/scan-build/c++-analyzer t.cpp
scan-build: Removing directory '/tmp/scan-build-2012-06-14-6' because it contains no reports.

如何使 c++-analyzer 工作? Clang 在 Ubuntu 11.10 上的版本是 2.9。

编辑:我知道代码不正确。关键是 Clang 不会提示明显的错误。如果我将上面的代码粘贴到 .c 文件(没有 using ...),clang 会正确发出警告。

最佳答案

原因是:

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-September/011194.html

>>> When I run "clang --analyze" on my c++ source files individually I get reports,
>>> but none when using the scan-build tool.
>>
>> This is intended behavior. C++ support is still alpha and so it isn't enabled
>> by default in scan-build. It's really only intended to be used by those
>> currently hacking on the analyzer.
>>
>> If you want to enable C++ analysis, you must define the environment variable
>> CCC_ANALYZER_CPLUSPLUS.

关于c++ - clang 的扫描构建不适用于简单的 cpp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com