It seems that SonarQube is lost with function pointers.
When a function F is called only through a pointer, it is deemed as unused, as all the functions it calls (if these functions are actually called only by F).
Do you confirm ?
Note that for the case I’m working on, in spite of the use of function pointer, the pointer’s value is set statically.
Remind me of your context for this? I.e. are you on SonarQube Cloud? SonarQube for IDE (flavor and version)? SonarQube self-managed (flavor and version)?
Nothing related to this rule is jumping out at me in Jira. It looks like we last worked on it direclty in August. But that doesn’t mean other changes don’t impact it. I’ve flagged this for the language experts.
No, this is not how the analyzer is supposed to work. As soon as any reference is made to the function, for instance to take its address, it should be considered as called.
As requested by @ganncamp, the analysis log might help, along with some description of where the function is defined and where its address is taken.
Additionally, it could help if you can also provide a reproducer for the file where the address of the function is taken.
About the S5536 issues…
I just ran a Merge Request (to th emain branch, develop). I’ve got 11 issues. All of type cpp:S5536.
On a file I didn’t even touch…
In the issues card, they’re tagged as found during the analysis, but the last modifications on the concerned lines are several months/years old…
Not a recommendation, because as @Oodini said, they are full of generated code that would raise many issues. For now, I’m just trying to understand the situation, and especially if the function erroneously identified as never used are actually referenced from one of the analyzed files.
Recommendations will come later, when I have a better understanding.
If a function is called only through an on_*() function, managed by AutoMOC, this function and all the call graph from this function may be marked as unused.
The problem is when you get a such issue, it may be long to crawl to its Qt source. So these issues are tedious to manage. It should be great to be able to mark a function as a comment to say: “All the the functions called from this function (in a direct or indirect way) should be considered as called, even if this function is deemed as uncalled.”
I’m not sure about “functions called from this function”, because AFAICT this rule should detect them as used in the first place.
About marking a function with a comment, it is possible. If you mark a function with [[maybe_unused]], it will not be reported by this rule. So I hope this is going to solve your issue.
If it does not, as already requested, I will need more information to actually be able to investigate. Most probably a reproducer for the file where this function is defined, plus the code that triggers its call from the on_* function.