在linux上用g ++运行clang scan-build

时间:2016-05-17 16:52:34

标签: c++ clang++ scan-build

我有以下代码:

#include <iostream>
#include <memory>

using namespace std;

class A
{
    public:
        void foo() const;
};

void A::foo() const {}

std::unique_ptr<A> foo2()
{
    std::unique_ptr<A> pa(new A());
    return pa;
}

void
foo()
{
    const A& ra = *foo2();
    ra.foo();
}

int
main()
{
    foo();
    return 0;
}

我正在尝试使用clang的scan-build:

scan-build g++ --std=c++11 unique_ptr.cpp

该程序使用g ++编译并运行良好。 我使用的是CentOS和clang3.8以及g ++ 4.8.5。

错误讯息:

 error: no type named 'unique_ptr' in namespace 'std'
 std::unique_ptr<A> foo2()
 ~~~~~^

1 个答案:

答案 0 :(得分:3)

您应该使用:

pay

而不是:

scan-build g++ -std=c++11 unique_ptr.cpp

scan-build g++ --std=c++11 unique_ptr.cpp 有效(虽然-std没有),因为--std专门检查scan-build标志。

clang/tools/scan-build/libexec/ccc-analyzer中:

-std
相关问题