Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang doesn't know std::atomic_bool, but XCode does

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.

like image 367
Thomas Kappler Avatar asked Jan 03 '13 09:01

Thomas Kappler


2 Answers

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.

like image 119
Thomas Kappler Avatar answered Oct 18 '22 03:10

Thomas Kappler


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.

like image 4
Rodrigo Avatar answered Oct 18 '22 03:10

Rodrigo