cpp:S2156 false positive

  • What language is this for?
    C++
  • Which rule?
    cpp:S2156
  • Why do you believe it’s a false-positive/false-negative?
    The rule has an exemption: “This rule ignores protected functions in a final class that are overrides of a base class protected function.”, but it does not seem to be applied. As far as I can see, the code follows all prerequisites of the exemption, but the rule is flagged anyway.
  • Are you using
    • SonarQube - which version?
      Enterprise Edition Version 9.9 (build 65466)
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
class X {
protected:
    virtual void a() = 0;
};
class Y final : public X {
protected:
    void a() override {}
};

1 Like

For what it’s worth, it looks like the false positive is attributed to the protected specifier running off to the end of the class, and not that the function isn’t being exempted from the rule.

See Compiler Explorer

So if the class has other part as well, then a workaround would be to make sure that the protected section is not the last section.

1 Like

Hello @mtnpke, thank you for this reduced example (and thank you @torgeir.skogen for the investigation).

This is indeed a bug in our products. I created a ticket, and a fix for it is already on its way.

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