3
votes

I try to compile the simple code

#include <atomic>
int bar = 0;
void foo(std::atomic<int>&flag)
{ bar = flag; }

with clang++ 3.2 (downloaded as llvm 3.2 from llvm.org; on mac os.x 10.8.3 this fails with the error

/> clang++ -std=c++11 -stdlib=libc++ -O3 -march=native -c test.cc

In file included from test.cc:1:

/usr/include/c++/v1/atomic:576:17: error: first argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)

{return __c11_atomic_load(&__a_, __m);}
        ^                 ~~~~~

/usr/include/c++/v1/atomic:580:53: note: in instantiation of member function 'std::_1::_atomic_base::load' requested here

operator _Tp() const _NOEXCEPT          {return load();}
                                                ^

test.cc:5:9: note: in instantiation of member function 'std::_1::_atomic_base::operator int' requested here

bar = done;

When I use /usr/bin/clang++ instead (which comes with the OS or Xcode) it compiles just fine. The libc++ is that at /usr/lib/c++/v1 in both cases.

What am I missing? Is there another libc++ that comes with llvm 3.2 but which I'm missing? (I cannot find anything in the clang3.2 tree).

1
It rather seems like a library issue (spurious const) here. And no, libc++ comes within the LLVM umbrella so you should have the right one. - Matthieu M.
@MatthieuM. I don't understand. the libc++ at /usr/include/c++/v1 did not come with the llvm3.2 download, but with the OS. Yet xcode seems to have its own version (see answer). so what do you mean with "umbrella" - Walter
LLVM is an open-source project with a (relatively) clear goal, the LLVM umbrella refers to projects related to LLVM; mostly those projects are hosted within the LLVM SVN server. Clang, libc++ and lldb can be thought of as being hosted by LLVM for example. So, that being said, you might have a new LLVM and be using NOT the libc++ that is adapted for it but instead another libc++ lying around somewhere on your machine. - Matthieu M.

1 Answers

1
votes

Xcode now bundles libc++ within the Xcode.app directory. You can inspect this directory by control-clicking Xcode.app and choose "Show Package Contents".