Reputation: 5007
Reading CppCheck's List of Checks and the checkfunctions.h I noticed the feature:
Warn if a function is called whose usage is discouraged
I did not understand how to configure this, though. More specifically I want
cv::imwrite()
) to be discouraged. I am linking the pre-builts of this library so it would be hard (but not impossible) to change the source code to achieve itHow can I annotate these functions or how can I add them to CppCheck's list of "functions non grata"?
Upvotes: 1
Views: 1253
Reputation: 3037
The check uses configuration. Nothing is hardcoded. Write a custom cfg file and use --library
to load that.
You can write the cfg file manually, it is xml format. Or you can use the GUI (it is not the best GUI ever but imho it works).
If you have a function foo that is deprecated then you will write something like:
<function name="foo">
<warn severity="style" alternatives="bar" reason="Deprecated"/>
<arg nr="1"/>
</function>
You can specify a custom warning message also:
<function name="foo">
<warn severity="warning">Do not use foo(). Use bar() instead.</warn>
<arg nr="1"/>
</function>
For each argument that the function takes you need to provide a <arg>
.
Let me know if you have problems.
Upvotes: 4
Reputation: 43
I am not certain if there is a generic way to check the usage of all the third party functions. Probably @Daniel Marjamäki is the best person to answer this. But did you try creating a rule for it?
If you wish to check for the exact signature of the function, you could have something like this:
<?xml version="1.0"?>
<rule version="1">
<pattern>cv::imwrite\(\)</pattern>
<message>
<id>discouragedFunction</id>
<summary>The use of the function cv::imwrite is discouraged.</summary>
</message>
</rule>
Or if you want something more on the generic side, you could have something like this:
<?xml version="1.0"?>
<rule version="1">
<pattern>cv::[_a-zA-Z][_a-zA-Z0-9]+\(\)</pattern>
<message>
<id>discouragedFunction</id>
<summary>The use of the function opencv functions are discouraged.</summary>
</message>
</rule>
Upvotes: 3