Skip to content

Fix create_service() compile failure from can_be_nullptr trait (#1742)#3168

Open
PavelGuzenfeld wants to merge 1 commit into
ros2:rollingfrom
PavelGuzenfeld:fix/issue-1742-service-callback-nullptr
Open

Fix create_service() compile failure from can_be_nullptr trait (#1742)#3168
PavelGuzenfeld wants to merge 1 commit into
ros2:rollingfrom
PavelGuzenfeld:fix/issue-1742-service-callback-nullptr

Conversation

@PavelGuzenfeld
Copy link
Copy Markdown

Fixes #1742

AnyServiceCallback::set() (and GenericServiceCallback::set()) chose between two overloads using the detail::can_be_nullptr trait. Its non-QNX specialization probed the raw callable with decltype(std::declval<T &>() = nullptr), which is ill-formed for some callables/compilers — that disables both overloads and breaks compilation of create_service() for the affected callbacks.

This removes the trait and uses a single set() that stores the callback and then rejects it if the resulting std::function is empty (detail::callback_is_null() visits the variant). std::function's operator bool flags only genuine null targets such as a null function pointer; lambdas and bind expressions are never empty, so behaviour is unchanged. The duplicated overload pair in both headers collapses to one.

Adds regression tests for function-pointer and std::function callbacks (which previously failed to compile) and null-rejection for both.


Some of this change was produced with Claude Opus 4.8 (Anthropic).

…#1742)

The two set() overloads in AnyServiceCallback and GenericServiceCallback were
selected by detail::can_be_nullptr, whose non-QNX specialization probed the raw
callable with decltype(std::declval<T&>() = nullptr). That expression is
ill-formed for some callables/compilers, disabling both overloads and breaking
compilation of create_service() (and the generic service) for affected
callbacks.

Replace the trait with a single set() that stores the callback and then checks
the resulting std::function for emptiness via detail::callback_is_null(), which
visits the variant. std::function's operator bool flags only genuine null
targets (e.g. a null function pointer); lambdas and bind expressions are never
empty, so behavior is preserved while the brittle SFINAE is removed. This also
collapses the duplicated overload pair in both headers.

Add regression tests for function-pointer and std::function callbacks (which
previously failed to compile) and null-rejection for both.

Fixes ros2#1742

Generated-by: Claude Opus 4.8 (Anthropic)
Signed-off-by: Pavel Guzenfeld <pavelguzenfeld@gmail.com>
@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/issue-1742-service-callback-nullptr branch from e81ee96 to c9e0184 Compare June 6, 2026 22:24
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.

QNX support: can_be_nullptr causes build failure with packages using create_service()

1 participant