Skip to content

Avoid Mimick argument matching for unconditional patches - #3221

Open
ukis666 wants to merge 1 commit into
ros2:rollingfrom
ukis666:fix/clang-function-pointer-warning-2488-clean
Open

Avoid Mimick argument matching for unconditional patches#3221
ukis666 wants to merge 1 commit into
ros2:rollingfrom
ukis666:fix/clang-function-pointer-warning-2488-clean

Conversation

@ukis666

@ukis666 ukis666 commented Aug 11, 2026

Copy link
Copy Markdown

Description

mocking_utils::Patch currently configures replacements through
mmk_when(..., mmk_any(...)). Although each argument is matched as ANY,
Mimick still instantiates its generic comparison code for the argument types.

For rcl_logging_configure_with_output_handler, one of those arguments is a
function pointer. Clang therefore diagnoses the generated ordered comparisons
with -Wordered-compare-function-pointers.

This change avoids instantiating Mimick's generic argument-matcher path when
mocking_utils::Patch installs an unconditional replacement. Instead, the
replacement trampoline is installed directly through Mimick's mock creation
API.

Patch does not expose selective argument matching; its current use configures
a replacement for every invocation. This preserves the intended unconditional
replacement behavior while avoiding Mimick's generic argument-matcher path.

With that matcher path no longer instantiated, function-pointer arguments do
not generate ordered comparisons and the Clang-specific diagnostic suppression
in test_utilities.cpp can be removed.

Fixes #2488

Is this user-facing behavior change?

No. This only changes the internal test mocking utility.

Did you use Generative AI?

Yes. Generative AI was used to assist with analysis and validation of the change.

Additional Information

The change was validated against ROS 2 Rolling using
rostooling/setup-ros-docker:ubuntu-resolute-ros-rolling-ros-base-latest.

  • test_utilities builds and passes with Clang 21.1.8 and
    -Werror=ordered-compare-function-pointers.
  • A full rclcpp test build completes successfully with the same warning
    promoted to an error.
  • The full test run contains 151 tests and reports 3 failures. A clean Rolling
    control run in the same environment reports the same 3 failures:
    test_client, test_subscription, and test_subscription_options.
    No additional failures were introduced by this change in the validation
    environment.
  • test_utilities also builds and passes with GCC.

Upstream CI can provide additional validation across the supported platform
matrix.

Avoid instantiating Mimick's generic argument matcher when a test patch applies to every invocation. This prevents Clang from compiling ordered comparisons for function pointer arguments and allows the temporary warning suppression to be removed.

Signed-off-by: Ulaş <36420486+ukis666@users.noreply.github.com>
@ukis666
ukis666 marked this pull request as ready for review August 11, 2026 10:21
@mergify

mergify Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

mmk_when(proxy_(any<ArgTs>()...), .then_call = type_erased_trampoline);
struct mmk_mock_options options {};
options.sentinel_ = 1;
mock_ = mmk_mock_create_internal(target_.c_str(), type_erased_trampoline, options);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a broken patch could never go unnoticed before.
the raw internal call sidesteps that safety net, i believe.
it can return an invalid handle, mock_ stays useless, and replace_with returns as if everything worked.
the consequence is nasty specifically because this is a test utility...

mmk_when(proxy_(any<ArgTs>()...), .then_call = type_erased_trampoline);
struct mmk_mock_options options {};
options.sentinel_ = 1;
mock_ = mmk_mock_create_internal(target_.c_str(), type_erased_trampoline, options);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i do not think using internal methods and members are correct thing to do here. could it use public stub APIs instead of mmk_mock_create_internal especially with options.sentinel_?

@fujitatomoya

Copy link
Copy Markdown
Collaborator

Yes. Generative AI was used to assist with analysis and validation of the change.

can you disclose which AI tools and models are used to create this PR?

@fujitatomoya

Copy link
Copy Markdown
Collaborator

according to the test, i think we need to do the test with source build instead of released pacakges.
can you go through https://docs.ros.org/en/rolling//Get-Started/Installation/Alternatives/Ubuntu-Development-Setup.html to make sure all the tests are pass?

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.

Clang warning: ordered comparison of function pointers (Rolling)

2 participants