Skip to content

Conversation

@rgetz
Copy link
Contributor

@rgetz rgetz commented Jan 16, 2026

This change updates CheckUnusedFunctions to skip functions explicitly marked as ignored by the library configuration, both during per-file checks and whole-program analysis. This prevents false positives for known framework hooks, callbacks, or externally-used symbols that should be intentionally excluded from unused-function diagnostics.

I have found this very useful when looking at libraries, and creating a self.cfg file which looks like:

   <function name="iio_context_get_pdata">
     <ignorefunction>true</ignorefunction>
   </function>

This change updates CheckUnusedFunctions to skip functions explicitly
marked as ignored by the library configuration, both during per-file
checks and whole-program analysis. This prevents false positives for
known framework hooks, callbacks, or externally-used symbols that should
be intentionally excluded from unused-function diagnostics.

Signed-off-by: Robin Getz <[email protected]>
@rgetz rgetz force-pushed the rgetz-ignore-functions branch from b08bd93 to cd49158 Compare January 16, 2026 21:39
@sonarqubecloud
Copy link

@chrchr-github
Copy link
Collaborator

Currently, the attribute is used in CheckClass to allow certain virtual functions to be called in constructors. I doubt that it is much used, but I'm not sure if we should repurpose/dual-purpose this feature. ignorefunction is also quite unspecific, and there is no documentation.
A test should be added.

@rgetz
Copy link
Contributor Author

rgetz commented Jan 16, 2026

Thanks for pointing this out.

You’re right that ignorefunction is not documented in the reference PDF. However, it is a first-class element in the cfg schema itself, cppcheck/cfg/cppcheck-cfg.rng defines

<element name="ignorefunction">
    <ref name="DATA-BOOL"/>
</element>

which implies this attribute is intended to be a general library configuration signal rather than something check-specific or accidental. (happy to be corrected in my understanding if I'm wrong).

Given that:

  • There is no documented restriction that ignorefunction is exclusive to CheckClass
  • The name itself is generic (unlike e.g. constructor-specific attributes)
  • The schema allows it for any function symbol

…using it to suppress unused-function diagnostics seems consistent with the schema-level intent: “this function should be ignored by certain analyses.” Today, unused-function reporting ignores that signal, which leads to false positives even when the user has explicitly annotated the function in the library config...

That said, I agree on two points:

  • Documentation gap – the reference PDF should either document ignorefunction and describe its semantics, or explicitly scope it if it is meant to be limited.
  • Tests – I will add a regression test covering unused-function suppression via ignorefunction (both per-file and whole-program modes). (based on feedback, if this is the right direction or not).

If folks prefer to keep ignorefunction narrowly scoped to class analysis, I’m open to introducing a more specific cfg attribute for unused-function suppression instead. But given the existing schema and naming, honoring it in CheckUnusedFunctions feels like the least surprising behavior for users today...

Just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants