5

I'm trying to compile C++11 code that declares a variable of type std::atomic_bool. This is on Mac OS 10.8.2 with clang:

clang --version Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix 

clang complains about std::atomic_bool:

clang++ -c -stdlib=libc++ -msse4 -std=c++11 -Wno-unused-parameter -I. -o query.o query.cpp In file included from query.cpp:1: [...] ./threadutils.h:33:10: error: no type named 'atomic_bool' in namespace 'std'; did you mean 'atomic_long'? std::atomic_bool work; 

However, the same file compiles fine in an XCode project using the same compiler. So I assume I'm missing something in my manual compiler invocation.

I tried a few variations such as -std=c++0x and -std=gnu++11, to no avail.

1
  • Show us some code. It looks like clang 3.1 supports atomics so perhaps it's a coding issue. Commented Jan 3, 2013 at 9:36

2 Answers 2

5

I figured it out. Unfortunately I planted a false flag into my question: it didn't work in XCode either, I had a different version of the source file imported there.

The problem was that C++11 defines "a named type atomic_bool corresponding to the specified atomic<bool>", but clang doesn't support that.

Renaming the type from atomic_bool to atomic<bool> fixed it.

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

Comments

5

I found the same problem. In my case I resolved it by including atomic:

#include <atomic> static std::atomic_bool varname; 

After this, I could call g++ with std=c++11 on a Linux (Ubuntu) as well as compile on XCode.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.