2

I have the following code:

#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;
}

I am trying to use clang's scan-build:

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

This program compiles and runs fine with g++. I am using CentOS and clang3.8 and g++4.8.5.

Error Message:

 error: no type named 'unique_ptr' in namespace 'std'
 std::unique_ptr<A> foo2()
 ~~~~~^
gudge
  • 1,053
  • 4
  • 18
  • 33

1 Answers1

4

You should use:

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

Instead of:

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

-std works (while --std doesn't) because scan-build checks specifically for the -std flag.

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

if ($Arg =~ /^-std=/) {
  push @CompileOpts,$Arg;
  next;
}
Binary Birch Tree
  • 15,140
  • 1
  • 17
  • 13