C++ override virtual functions detected as "duplicated code"

Hi,
I have an issue with a C++ project where Sonar detects many lines duplicated and I don’t understand why.

I have a C++ class (interface) with many functions marked as “pure virtual” (= 0).
Then I have 2 different sub-classes inheriting from this interface, so defining all these virtual functions (override).

But during analysis, Sonar detects “duplicated code” between the headers of these 2 sub-classes, because these functions are the same in both files (which seems fully correct for C++). The implementation of these functions in the source files are very different, so it is not a question of being able to merge these classes.

I don’t see how I could avoid that and I imagine that this is an issue (false positive) on Sonar side?

Best regards,
Alexandre

(The project is hosted on Bitbucket with Sonar running on Appveyor CI).

Hi @habersaa,

code duplication is language agnostic and based on tokens only, have a look at Duplications section on the documentation page: Duplications.