0028439: Configuration - compilation error when using thread_local within XCode 7...
authorkgv <kgv@opencascade.com>
Thu, 9 Feb 2017 12:52:59 +0000 (15:52 +0300)
committerapn <apn@opencascade.com>
Thu, 9 Feb 2017 13:16:23 +0000 (16:16 +0300)
__has_feature(cxx_thread_local) check has been added
for using thread_local keyword within CLang.

adm/cmake/occt_defs_flags.cmake
src/Standard/Standard_Failure.cxx

index 65fff6e..8f4872b 100644 (file)
@@ -122,7 +122,10 @@ if(MINGW)
   add_definitions(-D_WIN32_WINNT=0x0501)
   # workaround bugs in mingw with vtable export
   set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
-elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
+elseif ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
+  # CLang can be used with both libstdc++ and libc++, however on OS X libstdc++ is outdated.
+  set (CMAKE_CXX_FLAGS "-std=c++0x -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
+elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
   set (CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
 endif()
 
index 83e52e9..b7a4d14 100644 (file)
@@ -58,12 +58,18 @@ static void deallocate_message(Standard_CString aMessage)
   }
 }
 
-// Define Standard_THREADLOCAL modifier as C++11 thread_local keyword
-// where it is available.
-#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER > 1400) || \
-    (defined(__clang__)) /* assume standard CLang > 3.3 or XCode >= 8 */ || \
-    (defined(_MSC_VER) && _MSC_VER >= 1900) /* MSVC++ >= 14 */ || \
-    (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) /* GCC >= 4.8 */
+// Define Standard_THREADLOCAL modifier as C++11 thread_local keyword where it is available.
+#if defined(__clang__)
+  // CLang version: standard CLang > 3.3 or XCode >= 8 (but excluding 32-bit ARM)
+  // Note: this has to be in separate #if to avoid failure of preprocessor on other platforms
+  #if __has_feature(cxx_thread_local)
+    #define Standard_THREADLOCAL thread_local
+  #else
+    #define Standard_THREADLOCAL
+  #endif
+#elif (defined(__INTEL_COMPILER) && __INTEL_COMPILER > 1400) || \
+      (defined(_MSC_VER) && _MSC_VER >= 1900) /* MSVC++ >= 14 */ || \
+      (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) /* GCC >= 4.8 */
   #define Standard_THREADLOCAL thread_local
 #else
   #define Standard_THREADLOCAL