Rule cpp:S4998 false positive for overriden functions

Hi. We have a third-party library and we inherit a class from it. One of the virtual functions violates the rule cpp:S4998 (Replace this use of “unique_ptr” by a raw pointer or a reference (possibly const)) and Sonar is correct here. But also Sonar reports a warning for overridden function in our class which we would like to avoid because we can’t change the third-party library and we have to use the function signature provided by it. An example:

// third party lib
class ThirdPartyClass
{
    // This is bad, but we can't change it
    virtual void foo(const std::unique_ptr<Something>& pointer);
};

// our code
class Child : public ThirdPartyClass
{
    // we have cpp:S4998 here
    void foo(const std::unique_ptr<Something>& pointer) override;
};

So, maybe it’s possible to check such rules only for the base class?

Hey @mkhachayants !

As noted here:

What version of what product(s) are you using which raise an FP here?

Hi! We use SonarQube server 10.5.1.90531 and SonarScanner 5.0.1.3006

Hello @mkhachayants,

We know that some of our rules report “valid” issues on function signatures, but it’s not possible to act on them, because the developer has no control over the function signature (being an override is one prominent case of that situation).

We would like to tackle this problem globally, and I added this rule to the list of affected rules.

Thank you for reporting it!

2 Likes

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