Fix create_service() compile failure from can_be_nullptr trait (#1742)#3168
Open
PavelGuzenfeld wants to merge 1 commit into
Open
Fix create_service() compile failure from can_be_nullptr trait (#1742)#3168PavelGuzenfeld wants to merge 1 commit into
PavelGuzenfeld wants to merge 1 commit into
Conversation
…#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>
e81ee96 to
c9e0184
Compare
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 #1742
AnyServiceCallback::set()(andGenericServiceCallback::set()) chose between two overloads using thedetail::can_be_nullptrtrait. Its non-QNX specialization probed the raw callable withdecltype(std::declval<T &>() = nullptr), which is ill-formed for some callables/compilers — that disables both overloads and breaks compilation ofcreate_service()for the affected callbacks.This removes the trait and uses a single
set()that stores the callback and then rejects it if the resultingstd::functionis empty (detail::callback_is_null()visits the variant).std::function'soperator boolflags 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::functioncallbacks (which previously failed to compile) and null-rejection for both.Some of this change was produced with Claude Opus 4.8 (Anthropic).