Do not put a concept in an exported template parameter list - #260
Merged
Merged
Conversation
GCC 14 does not encode a template parameter type-constraint in the mangled name; Clang 18+ does. On an explicitly instantiated template the two compilers therefore produce different symbols: GCC _ZN13tensorwrapper8generate21generate_eigen_systemIdEE... Clang _ZN13tensorwrapper8generate21generate_eigen_systemITkN3wtf8concepts13FloatingPointEdEE... The wheels are built by GCC, so a Clang consumer of the C++ SDK asks for a symbol the library never exports. SCF test_cmake_build (ubuntu-latest, clang-18) failed with 8 undefined references to generate_eigen_system<float> and <double> from its Catch2 template tests, while the gcc-14 leg linked fine -- the giveaway that this is a mangling divergence and not a missing instantiation. Fix: declare the five exported templates with `typename T` and enforce the requirement with a static_assert in each definition. Internal helpers that are never exported (add_noise_impl, the *_spacing helpers, sort_eigenvalues) keep their constraints. Verified by compiling each patched TU with BOTH g++-14 and clang++-18: the emitted manglings are now identical. Reduced repro confirmed the mechanism (a GCC-built .so links against a GCC consumer and fails against a Clang one; clang -fclang-abi-compat=17 also links, confirming Clang 18 introduced the constrained mangling). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
🚀 [bumpr] Bumped! |
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 8 undefined references that fail SCF
test_cmake_build (ubuntu-latest, clang-18).Root cause
GCC 14 does not encode a template parameter’s type-constraint in the mangled name. Clang 18+ does. On an explicitly instantiated template the two produce different symbols:
The wheels are built by GCC, so a Clang consumer of the C++ SDK asks for a symbol the library never exports. The gcc-14 leg links fine — that asymmetry is the giveaway that this is a mangling divergence, not a missing instantiation.
The call sites are SCF’s own Catch2 template tests (
eigen_normal.cpp,jacobi_normal.cpp), which instantiate over<float>and<double>.Reduced repro (confirms the mechanism)
A constrained template +
extern template+ explicit instantiation, library built by g++-14:_ZN2tw3genIdEE..._ZN2tw3genITkN3wtf8concepts13FloatingPointEdEE...-fclang-abi-compat=17_ZN2tw3genIdEE...The
-fclang-abi-compat=17row confirms Clang 18 introduced the constrained mangling. That flag is not a usable fix here — these are public wheels, and third-party Clang consumers cannot be required to pass a compatibility flag.The fix
Declare the five exported templates with
typename Tand enforce the requirement with astatic_assertin each definition. Internal helpers that are never exported (add_noise_impl, the*_spacinghelpers,sort_eigenvalues) keep their concept constraints.Affected:
add_noise(×2),generate_eigen_system,generate_eigenvalues,random_orthogonal_matrix. A scan of the other ten ecosystem repos found no other constrained-and-explicitly-instantiated templates.Verification
Each patched TU compiled with both g++-14 and clang++-18; the emitted manglings are now identical in all four files.
Behaviour note
Misuse moves from a call-site constraint error to a
static_assertin the definition. In practice these templates are explicitly instantiated forfloat/doubleonly, so any otherTwas already a link error.🤖 Generated with Claude Code