Skip to content

Callback object comparison not working #9423

Closed
@SeppoTakalo

Description

@SeppoTakalo

Description

Example code:

#include "mbed.h"

void another_callback(nsapi_event_t status, intptr_t param)
{
    printf("another_callback called\r\n");
}

mbed::Callback<void(nsapi_event_t, intptr_t)> test(mbed::Callback<void(nsapi_event_t, intptr_t)> arg)
{
    return arg;
}

int main()
{
    printf("Status callback example!\r\n");

    mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb = callback(&another_callback);
    mbed::Callback<void(nsapi_event_t, intptr_t)> another_cb = test(status_cb);

    if (another_cb == status_cb) {
        printf("Callbacks are the same\r\n");
    } else {
        printf("Callbacks are NOT SAME\r\n");
    }
}

I would expect callbacks to return true for the comparison operation as those are exacly copies of the same object.

Directly copying the callbacks leads the comparison to return true, but passing it as a parameter to functions seems to lead it to return false.

Issue request type

[ ] Question
[ ] Enhancement
[X] Bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions