3

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).

3
  • 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. Commented Apr 25, 2013 at 14:59
  • @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" Commented Apr 25, 2013 at 17:13
  • 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. Commented Apr 25, 2013 at 17:34

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

There is indeed another libc++ at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/ (strange directory name with Toolchains) and its atomic differs by having __a_ declared as mutable. And this solves the problem. What I still don't get, is why there are these two different versions on my laptop. Are there also different versions of the abi?
Xcode changed the location of libc++, from /usr/include to internal. Likely the installer left /usr/include instead of deleting it. The same abi, __1, is still current.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.