Skip to content

Commit 463168a

Browse files
n01roz-agent
authored andcommitted
Resolve ambiguous factory spec. with nvcc+GCC (pybind#6011)
Explicitly specify the 4th template parameter in the single-factory partial specialization of `factory` to disambiguate it from the dual-factory specialization when compiled with nvcc + GCC 14. Fixes pybind#5565. Co-authored-by: Oz <oz-agent@warp.dev>
1 parent 16ef2e3 commit 463168a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

include/pybind11/detail/init.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,15 @@ template <typename CFunc,
370370
struct factory;
371371

372372
// Specialization for py::init(Func)
373+
// Note: The 4th template parameter `void_type()` is explicitly specified to resolve a
374+
// template ambiguity with the dual-factory specialization below when compiled with
375+
// nvcc + GCC (see #5565). Without it, both specializations match equally well for the
376+
// single-factory case, since the 4th parameter defaults to
377+
// `function_signature_t<void_type(*)()>` = `void_type()`, which the dual-factory
378+
// specialization can also decompose as `AReturn(AArgs...)` with `AReturn=void_type`
379+
// and `AArgs={}`.
373380
template <typename Func, typename Return, typename... Args>
374-
struct factory<Func, void_type (*)(), Return(Args...)> {
381+
struct factory<Func, void_type (*)(), Return(Args...), void_type()> {
375382
remove_reference_t<Func> class_factory;
376383

377384
// NOLINTNEXTLINE(google-explicit-constructor)

0 commit comments

Comments
 (0)