Std :: atomic not supported by clang?

I am trying to use std :: atomic with clang. However, whenever I try to include the atomic header file ( #include <atomic> ), I get the message "atom not found". Please note that during compilation I include - std=c++11 -stdlib=libc++ . What am I missing?

The clang version I'm using is 3.2.

+6
source share
3 answers

The clang version I'm using is 3.2.

Clang added atomic support in two different versions in accordance with LLVM CXX Status . The first was Clang 3.1, and the second was Clang 3.2.

I think you can check it using:

 #if defined(__clang__) # if __has_feature(cxx_atomic) # define CLANG_CXX11_ATOMICS 1 # endif #endif 

Then in your code:

 #if CLANG_CXX11_ATOMICS # include <atomic> #endif ... #if defined(CLANG_CXX11_ATOMICS) # define MEMORY_BARRIER() std::atomic_thread_fence(std::memory_order_acq_rel) #elif defined(__GNUC__) || defined(__clang__) # define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory") ... #endif 

I can only say "I think" because cxx_atomic not documented in the Clang Language Extensions . However, it is found when searching for the LLVM site: "cxx_atomic" site: llvm.org .

There is also an open question about the CFE user mailing list: How to check for std :: atomic?


Please note that at compile time I include -std = c ++ 11 -stdlib = libc ++. What am I missing?

You can use one of these CLA / LLVM C ++ for this, which is actually just C ++ 03 but pretend to be C ++ 11. This has caused me a lot of problems in the past because we support many compilers and platforms.

The following is a test that Jonathan Wackel helped us create to see if it really was a C ++ 11 library, or one of the fake Apple C ++ 11 libraries:

 // Visual Studio began at VS2010, http://msdn.microsoft.com/en-us/library/hh567368%28v=vs.110%29.aspx. // Intel and C++11 language features, http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler // GCC and C++11 language features, http://gcc.gnu.org/projects/cxx0x.html // Clang and C++11 language features, http://clang.llvm.org/cxx_status.html #if (_MSC_VER >= 1600) || (__cplusplus >= 201103L) # define CXX11_AVAILABLE 1 #endif // Hack ahead. Apple standard library does not have C++ unique_ptr in C++11. We can't // test for unique_ptr directly because some of the non-Apple Clangs on OS X fail the same // way. However, modern standard libraries have <forward_list>, so we test for it instead. // Thanks to Jonathan Wakely for devising the clever test for modern/ancient versions. // TODO: test under Xcode 3, where g++ is really g++. #if defined(__APPLE__) && defined(__clang__) # if !(defined(__has_include) && __has_include(<forward_list>)) # undef CXX11_AVAILABLE # endif #endif 
+2
source

Your version of Clang is deprecated. You should get the latest version either from the package manager or from http://clang.llvm.org/ .

+1
source

Did you specify -I /path/to/your/c++ (or almost equivalently, -cxx-isystem /path/to/your/c++ ) so that clang++ can find its location?

If you think that you do not need, try clang++ -print-search-dirs confirm.

+1
source

Source: https://habr.com/ru/post/1200134/


All Articles