Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang 3.1 can't see unique_ptr?

Tags:

c++

c++11

clang

I've just started playing around with clang and tried to compile the following sample program:

#include <memory>
#include <iostream>

int main()
{
    std::unique_ptr<unsigned> u(new unsigned(10));
    std::cout << *u << std::endl;
    return 0;
}

When I compile I get the following errors:

$ clang++ helloworld.cpp 
helloworld.cpp:6:10: error: no member named 'unique_ptr' in namespace 'std'
    std::unique_ptr<unsigned> u(new unsigned(10));
    ~~~~~^
helloworld.cpp:6:29: error: expected '(' for function-style cast or type construction
    std::unique_ptr<unsigned> u(new unsigned(10));
                    ~~~~~~~~^
helloworld.cpp:6:31: error: use of undeclared identifier 'u'
    std::unique_ptr<unsigned> u(new unsigned(10));
                              ^
helloworld.cpp:7:19: error: use of undeclared identifier 'u'
    std::cout << *u << std::endl;
                  ^
4 errors generated.

I am using Clang 3.1 on Mac OS X:

$ clang++ --version
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix

Any ideas why this wouldn't compile?

like image 854
Graeme Avatar asked Aug 07 '12 20:08

Graeme


1 Answers

I got it to compile by using

clang++ test.cpp  -std=c++11 -stdlib=libc++
like image 129
Andrea Bergia Avatar answered Sep 20 '22 14:09

Andrea Bergia