Unused function

Hi,

I am using SonarCloud for C++ with the scanner 6.66.

I get quite often S5536 issues (" Functions that are not used in a project should be removed"), for functions actually used.

I am studying now 4 occurrences of this issue:

  • 1st case: constructor whose one argument was implicitely converted ; I added the explicit conversion, and it the issue disappeared
  • 2nd case: the function is called from a list of arguments, and is called from a Qt slot (directly or indirectly)
  • 3rd case: the function is static, and has an argument which doesn’t respect a pattern
  • 4th case: the function is called from a Qt slot (directly or indirectly)

Hey @Oodini

Always appreciate your reports, but our devs need code samples in order to investigate effectively.

Hi,

Here is a precise scenario. S5536 is raised when a static member function is called from within one of the class’s function, without the scope operator. At least when the calling function is static.

class Foo
{
    static void Bar1() {};
    static void Bar2() { Bar1(); };   // Bar1 unused
    // static void Bar2() { Foo::Bar1(); };   // OK}
;

Hi @Oodini,

I tried to reproduce your issue, but in my test, the call to Bar1 was detected, as you can see here.

Could you provide us with a full project that can showcase the issue? (maybe an open-source project that you would analyze on SonarQube Cloud)

No, I can’t, it isn’t open source (and anyway, I am too ashamed on this legacy code :)).

I must confess I havn’t tested the sample I provided, but I have “cleaned” some issues by adding this scope operator for static functions.

I am going to setup an empty open source project to be able to submit some problematic code to Sonar.

1 Like

This is what I had in mind. Thank you for making this effort!