Environment:
- Product: SonarQube Server
- Version: 2025.4.4.119049
- Language: C++
- Analysis type: Pull request analysis
- Metric: new_duplicated_lines_density
Problem description:
SonarQube reports duplicated lines between two implementations of a
C++ interface class
The duplicated sections consist of interface/implementation boilerplate and
Doxygen documentation references. We already use \copydoc in the
implementation in order to avoid duplicating the documentation text. From a
C++ design perspective, the repeated declarations and override methods are
required by the interface/implementation relationship and cannot be factored
out without changing the API or reducing readability.
The duplication is therefore not accidental copy-paste. It is caused by a
common and unavoidable C++ pattern: an interface declares the virtual methods,
while the implementation has to repeat the corresponding method declarations
and definitions.
Expected behavior:
The duplication detector should avoid reporting or significantly reduce
duplication for unavoidable C++ interface/implementation constructs, especially
when the implementation uses Doxygen \copydoc instead of repeating the full
documentation.
Alternatively, SonarQube should provide a documented way to exclude such
constructs from duplication detection without excluding the complete files.
Actual behavior:
The pull request receives duplicated-code findings or an increased
new_duplicated_lines_density value for these interface/implementation
constructs.
Impact:
This produces a misleading duplication result and can fail the quality gate,
although the code follows a standard C++ design pattern and the documentation
has already been deduplicated using \copydoc.
Reproducer:
The following reduced pattern reproduces the situation:
class IExample
{
public:
virtual ~IExample() = default;
//! Performs the operation.
//!
virtual void perform() = 0;
};
class ExampleA final : public IExample
{
public:
~ExampleA() override = default;
//! \copydoc IExample::perform()
//!
void perform() override;
};
class ExampleB final : public IExample
{
public:
~ExampleB() override = default;
// THE FOLLOWING COMMENT IS MARKED AS DUPLICATION
//! \copydoc IExample::perform()
//!
void perform() override;
};


