Repository navigation
Support noexcept callables in function_traits - #3322
Merged
Merged
Conversation
noexcept has been part of the function type since C++17, so noexcept free functions, function pointers, lambdas and std::bind of noexcept functions or methods fell through to the primary function_traits template and failed to compile (e.g. as timer or subscription callbacks). Add noexcept specializations that forward to the existing ones. Fixes ros2#2654 Signed-off-by: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com>
KR-Ravindra
marked this pull request as ready for review
October 12, 2026 00:37
ABI Compliance Check✅ Verdict: compatible
✅
|
fujitatomoya
approved these changes
Oct 14, 2026
fujitatomoya
left a comment
Collaborator
There was a problem hiding this comment.
lgtm with green CI.
Collaborator
|
Pulls: #3322 |
ahcorde
approved these changes
Oct 14, 2026
mjcarroll
pushed a commit
that referenced
this pull request
Oct 20, 2026
The noexcept specializations added in #3322 make the rosdoc2 documentation build fail: Sphinx's C++ domain hits an internal AssertionError while resolving references in the function_traits specializations. Wrap the noexcept variants in \cond/\endcond so Doxygen skips them. They mirror the documented non-noexcept specializations, and the compiled code is unchanged. Signed-off-by: R Kent James <kent@caspia.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Description
Fixes #2654
Problem
Since C++17,
noexceptis part of the function type.function_traitshas no specializations fornoexceptcallables, so they fall through to the primary template, which then fails on&FunctionT::operator(). Callbacks like anoexceptfree function,[](int) noexcept {}, orstd::bind(&C::cb, this, _1)withvoid cb(int) noexceptdon't compile when passed to APIs that usefunction_traits.Fix
This adds
noexceptspecializations that forward to the existing ones. They cover free functions, function pointers,constcall operators (lambdas), andstd::bindofnoexceptmethods (const and non-const) and free functions, in every standard-library branch the file already handles. Callbacks are still not required to benoexcept, per the discussion in the issue.How tested
There's a new
TestFunctionTraits.noexcept_callablesgtest intest_function_traits.cpp. I couldn't runcolcon testlocally, so I compiled and rantest_function_traits.cppon its own against the header (it only needs the standard library):noexceptcase.gcc:14container),-Wall -Wextra -Werror: 8/8 pass, against 25 compile errors with the current header.cpplintwith the ament line length is clean. I haven't runament_uncrustify.Is this user-facing behavior change?
Yes:
noexceptcallables can now be used as callbacks.Did you use Generative AI?
Yes. The change, tests and this description were prepared with Claude Code (Claude Opus 5.5), an AI agent operated by KR-Ravindra, who reviewed and tested it. The agent is pointed only at issues maintainers have confirmed and problems he has hit, not at producing contributions.