Skip to content

fix: work around clang 20/21 + libc++ compile failure in TEMPLATE_PRODUCT_TEST_CASE with differing arities#3173

Open
mvanhorn wants to merge 2 commits into
catchorg:develfrom
mvanhorn:fix/3115-clang-template-product-compile
Open

fix: work around clang 20/21 + libc++ compile failure in TEMPLATE_PRODUCT_TEST_CASE with differing arities#3173
mvanhorn wants to merge 2 commits into
catchorg:develfrom
mvanhorn:fix/3115-clang-template-product-compile

Conversation

@mvanhorn

Copy link
Copy Markdown

Description

Restructure the get_wrapper overload set emitted by INTERNAL_CATCH_TYPE_GEN in src/catch2/internal/catch_preprocessor.hpp so clang 20/21 no longer sees a conflicting deduction between the explicitly-specified template-template argument and the deduced parameter pack. Concretely, avoid mixing an explicitly-specified template <typename...> class argument with deduction against the same overload name: split the plain-type (TypeList<Ts...>) and template-template (TemplateTypeList<Cs...>) resolution into distinct helper names or a tag-dispatched trait, keeping the existing priority_tag ranking and identical resulting types so INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2 in src/catch2/internal/catch_template_test_registry.hpp needs at most a matching call-site rename. If a general restructuring proves too invasive, fall back to a narrowly scoped #if defined(__clang__) && __clang_major__ >= 20 && __clang_major__ < 22 alternative formulation, matching Catch2's existing compiler-workaround style.

Building Catch2 3.15.0's SelfTest suite fails under clang 20/21 with libc++ (observed on macOS and Alpine via meson wrapdb CI). The failing construct is TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", ..., std::tuple, (int, (int, double), (int, double, float))) in tests/SelfTest/UsageTests/Misc.tests.cpp:391. Clang reports "no matching function for call to 'get_wrapper'": the template-template overload of get_wrapper generated by INTERNAL_CATCH_TYPE_GEN in src/catch2/internal/catch_preprocessor.hpp (the priority_tag<1> overload returning TemplateTypeList<Cs...>) hits a "conflicting deduction 'std::tuple' against 'type-parameter-0-0'" substitution failure. The reporter notes clang 22 compiles it fine, so this is likely a clang 20/21 deduction bug, but those compiler versions ship on current macOS and Alpine toolchains, making a Catch2-side workaround valuable.

Closes #3115

GitHub Issues

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.09%. Comparing base (a15f718) to head (a0c7a39).

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #3173   +/-   ##
=======================================
  Coverage   91.09%   91.09%           
=======================================
  Files         204      204           
  Lines        8922     8922           
=======================================
  Hits         8127     8127           
  Misses        795      795           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rajpratham1 rajpratham1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. This is a minimal, targeted workaround for the Clang 20/21 template-template parameter issue, and it doesn't change public behavior. The added comment explains why the separate get_template_wrapper exists, which improves maintainability. One small suggestion would be to reference the relevant LLVM/Clang issue (or include the compiler error) in the comment so it's easier to remove the workaround once the upstream bug is fixed.

@mvanhorn

Copy link
Copy Markdown
Author

Thanks for the review. Good suggestion - added the reference in a0c7a39: the workaround comment now points at llvm/llvm-project#130778 (the Clang 20 'conflicting deduction' regression; its duplicate #138078 shows the exact diagnostic) and notes get_template_wrapper can be removed once Clang 21 is no longer supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests fail to compile under MacOS / Alpine

2 participants