fix c++20 build failure with pre-c++20 standard libraries - #268
Merged
Conversation
…ESENT parallel_for_each.h selected its concepts-based iterator_tag_dispatch on __TBB_CPP20_PRESENT, which only tests the language mode (__TBB_LANG >= 202002L). Toolchains that accept -std=c++20 but ship a pre-C++20 standard library then take the concepts branch and fail to find std::random_access_iterator; this broke installation on CRAN's macOS x86_64 machines, which pair Apple clang 14 with the macOS 11.3 SDK. Every other C++20 library dependency in these headers is already gated on __TBB_CPP20_CONCEPTS_PRESENT (or, for <compare>, on both the language and library feature-test macros), so parallel_for_each.h was the lone offender. This mirrors the upstream fix from oneTBB PR #1611 (issue #1552), first released in oneTBB 2022.1.0, and can be dropped once the bundled oneTBB is updated past 2022.0.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the installation failure on CRAN's
r-release-macos-x86_64machine(install log).
The problem
That builder is the only flavor pairing a C++20 language mode with a pre-C++20 standard library:
R's
Makeconfthere compiles with-std=gnu++20(nothing in ourconfigure/Makevars.insets astandard). Apple clang 14 accepts that and defines
__cplusplus == 202002L, but the libc++ bundled inthe 11.3 SDK does not provide the C++20 iterator concepts.
The bundled oneTBB selected its concepts-based iterator dispatch on the wrong macro:
so the concepts branch was taken and failed with
no member named 'random_access_iterator' in namespace 'std'.Every other C++20 library dependency in these headers is already gated correctly -- the
<concepts>includes in
flow_graph.h,_range_common.hand_mutex_common.hare behind__TBB_CPP20_CONCEPTS_PRESENT, and__TBB_CPP20_COMPARISONS_PRESENTchecks both the language andlibrary feature-test macros.
parallel_for_each.hwas the lone offender.Note this is not just our own
tbb.cpp: we ship these headers ininst/include, so any downstreampackage compiling under C++20 on that toolchain hits it too.
The fix
Switch the guard to
__TBB_CPP20_CONCEPTS_PRESENT, mirroring the upstream fix fromoneTBB PR #1611
(issue #1552), first released in oneTBB
2022.1.0. We bundle 2022.0.0, which predates it; the patch can be dropped once the bundled oneTBB is
updated past that.
__TBB_CPP20_CONCEPTS_PRESENTis hard-coded to0for clang in this TBB version (upstream masterstill does this:
#if !(__clang__) && defined(__cpp_concepts) && defined(__cpp_lib_concepts)), soclang builds fall back to the pre-C++20
iterator_categorytag dispatch -- which is already whatclang does for every other constraint in TBB, so this is consistent rather than a regression.
The change is recorded in
patches/cpp20_concepts.diff, following the existing convention.Verification
-fsyntax-onlyonsrc/tbb.cppand on a standalonetbb::parallel_for_eachTU undergnu++17,gnu++20andgnu++23: all clean.R CMD INSTALL --precleansucceeds, compiling with-std=c++20.tests/pass.sourceCppunder-std=c++20:tbb::parallel_for_eachover astd::vector(random-access dispatch) and a
std::list(forward dispatch) both produce correct results, so thefallback tag dispatch works at runtime and not merely syntactically.
static_assert(__TBB_CPP20_CONCEPTS_PRESENT == 0)against the bundled_config.hpasses on clang,confirming the concepts branch is now unreachable there regardless of SDK.
Reproduced locally against the macOS 11.3 SDK
Confirmed end-to-end by compiling against the actual SDK CRAN uses (extracted from
phracker/MacOSX-SDKs, which ships
_LIBCPP_VERSION 12000-- no__iterator/concepts.h, nostd::random_access_iterator):-isysroot MacOSX11.3.sdk -arch x86_64 -std=gnu++20reproduces the CRANfailure exactly: the same 7 errors at the same lines (429, 430, 437, 503, 631).
oneapi/tbb/*.hheaders (including the three preview-gated ones) compile cleanagainst that SDK at both
gnu++17andgnu++20, so no second missing C++20 library facility islurking behind the first error.
src/tbb.cppand a bare#include <RcppParallel.h>TU both compile clean against that SDK atgnu++17andgnu++20, covering the downstream include surface.