How to configure CppCheck to discourage usage of a function
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
- One of my own implemented functions to be discouraged
- A 3rdparty function (e.g. OpenCV's
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 it
How can I annotate these functions or how can I add them to CppCheck's list of "functions non grata"?
c++ c++11 visual-c++ static-analysis cppcheck
add a comment |
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
- One of my own implemented functions to be discouraged
- A 3rdparty function (e.g. OpenCV's
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 it
How can I annotate these functions or how can I add them to CppCheck's list of "functions non grata"?
c++ c++11 visual-c++ static-analysis cppcheck
add a comment |
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
- One of my own implemented functions to be discouraged
- A 3rdparty function (e.g. OpenCV's
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 it
How can I annotate these functions or how can I add them to CppCheck's list of "functions non grata"?
c++ c++11 visual-c++ static-analysis cppcheck
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
- One of my own implemented functions to be discouraged
- A 3rdparty function (e.g. OpenCV's
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 it
How can I annotate these functions or how can I add them to CppCheck's list of "functions non grata"?
c++ c++11 visual-c++ static-analysis cppcheck
c++ c++11 visual-c++ static-analysis cppcheck
asked Nov 14 '18 at 8:34
PhilLabPhilLab
2,6181247
2,6181247
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.
– PhilLab
Dec 20 '18 at 14:43
add a comment |
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>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295937%2fhow-to-configure-cppcheck-to-discourage-usage-of-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.
– PhilLab
Dec 20 '18 at 14:43
add a comment |
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.
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.
– PhilLab
Dec 20 '18 at 14:43
add a comment |
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.
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.
answered Nov 20 '18 at 6:02
Daniel MarjamäkiDaniel Marjamäki
2,164710
2,164710
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.
– PhilLab
Dec 20 '18 at 14:43
add a comment |
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.
– PhilLab
Dec 20 '18 at 14:43
1
1
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
if you create a simple opencv.cfg then feel free to upstream it. I would be happy to include it in cppcheck so everybody that uses opencv will get warned about its deprecated functions.
– Daniel Marjamäki
Nov 20 '18 at 6:06
Not to raise confusion:
cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.– PhilLab
Dec 20 '18 at 14:43
Not to raise confusion:
cv::imwrite()
is not widely discouraged at all. It just so happens that we have our own implementation which we prefer in our specific application only.– PhilLab
Dec 20 '18 at 14:43
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 14 '18 at 10:12
OptimatonOptimaton
3815
3815
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295937%2fhow-to-configure-cppcheck-to-discourage-usage-of-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown