False positive on cpp:S1250

Hi,

I’m using Developer Edition Version 8.1 (build 31237) with SonarCFamily 6.6.0 (build 13759)

The project was not yet updated to latest SonarCFamily, but I found nothing in the changelog that could help with this.

We have assignment operator coded this way :

/* operator */
MyClass& operator=(const MyClass& other) 
{
	/* Is it the same ? */
	if (&other == this)
		return *this;

	doSomething();
	
	return *this;
};

We obviously check for instance equality, but still we receive this error :

Check “other” for equality to “this” before proceeding with the assignment.

The rule suggests we use the pattern :

if(this != &other)
{
    doSomething();
}
return *this;

But I beleive the behaviour will be strictly the same.

1 Like

Hello @Guillaume_Schub and thank you for taking the time report this to us.

Upgrading to any version of CFamily starting from 6.8.0 will actually fix your problem.
The rule was deprecated in CPP-2435.

2 Likes

Hi,

Thanks for the answer. We managed to speed things up and migrated to latest CFamily, I confirme this is not reported as a bug anymore.

We consider the ticket as closed.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.