# C++: S5536 and function pointers

**URL:** <https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573>\
**Category:** SonarQube Cloud\
**Tags:** cfamily\
**Created:** [February 12, 2026, 8:43am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573 "2026-02-12T08:43:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 12, 2026, 8:43am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/1 "2026-02-12T08:43:58Z")

</div>

Hello,

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.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [February 12, 2026, 5:19pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/2 "2026-02-12T17:19:18Z")

</div>

Hi,

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)?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 13, 2026, 7:48am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/3 "2026-02-13T07:48:29Z")

</div>

- SonarCube Cloud
- SonarScanner CLI 8.0.1.6346
- Wrapper C++ 6.77
- SonarQube for IDE 9.6.0.16157

I’ll add that we get MANY S5536 issues these last days.  
Did the Soanr developers changed anything recently whic could explain the changed behavior ?

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [February 13, 2026, 12:49pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/5 "2026-02-13T12:49:58Z")

</div>

Hi,

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.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 13, 2026, 1:07pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/6 "2026-02-13T13:07:48Z")

</div>

OK, thank you.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [February 13, 2026, 1:10pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/7 "2026-02-13T13:10:09Z")

</div>

Hi,

Actually, I should have asked you for your analysis log. Can you post that, redacted as necessary?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 15, 2026, 12:35am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/8 "2026-02-15T00:35:00Z")

</div>

> [@Oodini](#):
>
> Do you confirm ?

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.

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 16, 2026, 8:45am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/11 "2026-02-16T08:45:52Z")

</div>

Hi again,

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…

I join you the file in a private message.

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 16, 2026, 8:53am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/12 "2026-02-16T08:53:27Z")

</div>

Hi @JolyLoic ,

OK, I note your answer.  
Nevertheless, as we use Qt, I suspect it is not so easy for Sonar to find the calls…

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 16, 2026, 9:22am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/13 "2026-02-16T09:22:43Z")

</div>

Is this function called through the signal/slot mechanism?  
Are the `moc_*` files analyzed?

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 16, 2026, 9:50am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/14 "2026-02-16T09:50:52Z")

</div>

They’re called in an indirect way through MOC files. But we don’t analyse these ones: too many Sonar errors in these generated codes…

---

<div class="post-metadata">

**Author:** ![jsinge](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jsinge](https://community.sonarsource.com/u/jsinge)\
**Post date:** [February 17, 2026, 8:59am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/15 "2026-02-17T08:59:59Z")

</div>

The question suprised me. Is there a recommendation to include the moc files in the sonar analysis?

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 17, 2026, 9:42am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/16 "2026-02-17T09:42:10Z")

</div>

Hi @jsinge,

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.

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 17, 2026, 9:50am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/17 "2026-02-17T09:50:04Z")

</div>

Hi,

> [@JolyLoic](#):
>
> 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.

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.”

---

<div class="post-metadata">

**Author:** ![jsinge](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jsinge](https://community.sonarsource.com/u/jsinge)\
**Post date:** [February 18, 2026, 1:27pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/19 "2026-02-18T13:27:19Z")

</div>

> [@Oodini](#):
>
> 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).

Maybe a little code example would also help with clarification?

Don’t forget c++ usually offers more than one way to do a thing 😉

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 19, 2026, 3:27pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/20 "2026-02-19T15:27:51Z")

</div>

> [@Oodini](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 20, 2026, 2:02pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/21 "2026-02-20T14:02:55Z")

</div>

> [@JolyLoic](#):
>
> I’m not sure about “_functions called from this function_”, because AFAICT this rule should detect them as used in the first place.

Sonar cannot detect them, because there isn’t any static call. It is injected dynamically by AutoMOC, during the runtime.

> [@JolyLoic](#):
>
> 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.

I’ll try, but I don’t think it will have a recursive effect. I don’t wish to tag all these functions as `[[maybe_unused]]`. If the “root” function is removed, I want to be warned that these indirect functions are not called anymore.

> [@JolyLoic](#):
>
> 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.

There is no static code calling the `on_*` function. Qt uses a kind of table of pointers to functions.

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 20, 2026, 3:39pm UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/22 "2026-02-20T15:39:37Z")

</div>

Hi @Oodini,

I’m shooting a little bit in the dark currently, which makes it hard to give good answers.

As far as I understand, you have:

- A root function, only called from files that are not analyzed (moc\_\*), but defined in a file that is analyzed
- Several functions, called from this root function only, also defined in an analyzed file.

Am I right?  
If not, could you provide a reproducer, or a sample project that would exhibit the problematic behavior?

---

<div class="post-metadata">

**Author:** ![Oodini](https://avatars.discourse-cdn.com/v4/letter/o/db5fbb/32.png) [@Oodini](https://community.sonarsource.com/u/Oodini)\
**Post date:** [February 24, 2026, 8:21am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/23 "2026-02-24T08:21:58Z")

</div>

Hello @JolyLoic

> [@JolyLoic](#):
>
> Am I right?

You are !

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [February 24, 2026, 8:43am UTC](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573/24 "2026-02-24T08:43:17Z")

</div>

In that case, the expected behavior is the following:

- The functions called from `root()` will be detected as used, no matter if `root()` is used or not, as long as `root()` is analyzed.
- `root()` will be detected as unused, but this can be avoided if it is marked `[[maybe_unused]]`.

As far as I understand, this behavior would be acceptable to you, but this is not what you observe: Other functions called from root are also detected as unused, which makes the use of `[[maybe_unused]]` unpractical.

It looks like there is an issue when analyzing the definition of `root()`, which prevents us from seeing the functions it calls. Can we have a reproducer of the file where `root()` is defined?

[Next page](https://community.sonarsource.com/t/c-s5536-and-function-pointers/177573.md?page=2)
