Problem misunderstanding with fuction within an IF statement

Hi. I'm new here and I'm not sure if this is the correct place to post this, sorry if it's not, but I appreciate your corrections.

Anyway, I have a problem with my project because the robot (2 motors) I control works fine when my code is like this

resp = object.function();
if (resp == -1)

but when looks like below, it doesn't work properly

if (object.function() == -1)

What I mean with that doesn't work properly is that at the beginning it works fine, but suddenly it fails
and I don't understand why. The only change between the proper behavior and the bad one is when I put my function within an IF statement.

I hope some of you can help me. thanks.

more details: object is an object of a class I created and the function return 0 or -1, but it takes some time.

There is no problem using a function call within an if test as long as the function returns a value. It does, however, mean that the returned value cannot be printed for debugging

More details of the function being called would be helpful

The essential details are missing:
What's the type of the function and the variable resp?

There was a member whose signature space used to say the answer is in the code you didn't post.

I have to wonder if your function is what fails or if this is a compiler-funny which usually is not the case.