Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

[PATCH] Enable C++11 features on Linux with Clang


I have sharing the patch to enable C++11 features in TTB if compiled with Clang. I did submit this patch few months ago and I don't see any relevant code changes in TBB (checked tbb44_20160526oss). Correct me if I am wrong.



Why this is needed? Our code base is compiled with C++14 for a long time and part of our code has to go through C++ interpreter which is done via Clang. Thus our code base must support GCC and Clang toolchains. We noticed that Clang was complaining once code with TBB was involved. We basically lost C++11 features, yet Clang is fully capable of delivering what TBB wants.

Currently we cannot use use C++11 features provided by Clang on Linux
with TBB because of GCC version check as Clang always reports GCC 4.2.1
compability version. In addition to that we should not require libc++ on
Linux. On Linux distributions Clang is mostly used with GNU libstdc++
for binary compatibility.

diff --git a/include/tbb/tbb_config.h b/include/tbb/tbb_config.h
index 58937e6..c416e15 100644
--- a/include/tbb/tbb_config.h
+++ b/include/tbb/tbb_config.h
@@ -160,7 +160,11 @@
 /** on OS X* the only way to get C++11 is to use clang. For library features (e.g. exception_ptr) libc++ is also
  *  required. So there is no need to check GCC version for clang**/
     #define __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT    (__has_feature(__cxx_variadic_templates__))
-    #define __TBB_CPP11_RVALUE_REF_PRESENT            (__has_feature(__cxx_rvalue_references__) && (__TBB_GCC_VERSION >= 40300 || _LIBCPP_VERSION))
+    #if (__APPLE__)
+ #define __TBB_CPP11_RVALUE_REF_PRESENT        (__has_feature(__cxx_rvalue_references__) && _LIBCPP_VERSION)
+    #else
+ #define __TBB_CPP11_RVALUE_REF_PRESENT        (__has_feature(__cxx_rvalue_references__))
+    #endif
 /** TODO: extend exception_ptr related conditions to cover libstdc++ **/
     #define __TBB_EXCEPTION_PTR_PRESENT               (__cplusplus >= 201103L && _LIBCPP_VERSION)
     #define __TBB_STATIC_ASSERT_PRESENT               __has_feature(__cxx_static_assert__)


0 Kudos
1 Reply

Hello David.

We did receive the patch that you have contributed; thank you for it. Unfortunately, the problem is bigger than that; there is a number of other C++11 features that Intel TBB uses and that depend on support in the C++ standard library.

We will provide a solution in the next release, but it will require TBB users to specify the actual version of GCC via a special macro. Unfortunately, we see no good way to automatically recognize which libstdc++ is in use, because its own version macro is set to a build date and is hard (if not impossible) to use for feature support detection.

0 Kudos