Disturbing bug in CPP language

I was having some unexpected results from a piece of code and took me a while to figure out what was going on…
Turns out I have wrong syntax on a line, but the compiler didn’t ever complain so the function was always returning the wrong result instead of failing compilation;

This, this should not compile:



if ( myOBJ->GetName().Equals(someString),ESearchCase::CaseSensitive) )
{
    //...
}


When fixing the call, all works:



if ( myOBJ->GetName().Equals(someString , ESearchCase::CaseSensitive) )


Anybody else experienced this weirdness before??
Funny thing is, compiler will only ignore the syntax error if I do it with the Equals() method.

Just tried and you’re right. This is just too weird.

Edit: Tried again and just realized I made a mistake. I only used one parenthesis at the end. Otherwise, the IDE and the compiler complains. So, I’m unable to replicate this issue.



if ( myOBJ->GetName().Equals(someString),ESearchCase::CaseSensitive)


So basically is like having:



if ((something), false)
{

}


Because ESearchCase::CaseSensitive is 0, ergo false. So the evaluation is always false. Comma operator: evaluates the first operand and discards the result, then evaluates the second operand and returns the result.

Are you sure it had 2 parenthesis at the end?

The comma operator strikes again!

Yes! just like posted.

So, it’s really weird, because I’m unable to compile that way:

Oh yes, I had it once too. Didn’t correct a line while refactoring code. Another programmer was like “why you wrote code likes this and why on Earth it compiles” :smiley:
This is a true devil.