#cppcheck--enable=alltest_token_pasting.cppCheckingtest_token_pasting.cpp...test_token_pasting.cpp:17:24:style:Variable'inside_function2'isassignedavaluethatisneverused.[unreadVariable]intinside_function2=0;^nofile:0:0:information:Cppcheckcannotfindalltheincludefiles(use--check-config for details) [missingIncludeSystem]
It doesn't see the unreadVariable error inside function1()--the one wrapped in the macro defined with IS_DEFINED(FOO) that uses token-pasting. How do I make this work?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If the token defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.
But well I guess it would be good if we were more clear about it.
And I am not against that we try to "handle" this like gcc/clang.. A goal of Cppcheck is that it will be possible to analyze code that does not strictly follow the C standard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like that a issue is created in the simplecpp issue tracker. Do you have a github account? https://github.com/danmar/simplecpp/issues
You can reduce your code example so it only demonstrates that the preprocessing is different to gcc/clang.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I moved the issue here to the simplecpp github repo as requested.
I've made a very hacky workaround where I first apply a patch to the code in the third-party library replacing each instance of the offending macro with equivalent code. Then I run cppcheck. When it completes I reverse the patch to get things back to where they were. Hopefully this is not the permanent solution, but it may be.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For information it would likely be better to utilize --library that will give Cppcheck a better understanding of the 3rd-party library... not just the compiler interface but also the semantics. But I guess it's a big job to provide the necessary configuration..
i.e. I have seen this construct in easylogging and we don't have a easylogging configuration yet.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't seem to get cppcheck (v1.90) to recognize my build macro that uses token pasting, though gcc has no problem with it. Here is some test code:
When i compile and run this with gcc (ubuntu v9.3.0) I see the expected output from both functions:
But when I run cppcheck:
It doesn't see the unreadVariable error inside function1()--the one wrapped in the macro defined with IS_DEFINED(FOO) that uses token-pasting. How do I make this work?
I would claim that you have undefined behavior in your code.
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
In chapter 6.10.1 , item 4, (page 148) it says:
If the token
defined
is generated as a result of this replacement process or use of thedefined
unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.But well I guess it would be good if we were more clear about it.
And I am not against that we try to "handle" this like gcc/clang.. A goal of Cppcheck is that it will be possible to analyze code that does not strictly follow the C standard.
I would like that a issue is created in the simplecpp issue tracker. Do you have a github account? https://github.com/danmar/simplecpp/issues
You can reduce your code example so it only demonstrates that the preprocessing is different to gcc/clang.
I moved the issue here to the simplecpp github repo as requested.
I've made a very hacky workaround where I first apply a patch to the code in the third-party library replacing each instance of the offending macro with equivalent code. Then I run cppcheck. When it completes I reverse the patch to get things back to where they were. Hopefully this is not the permanent solution, but it may be.
ah ok yes that is quite a hack.
For information it would likely be better to utilize
--library
that will give Cppcheck a better understanding of the 3rd-party library... not just the compiler interface but also the semantics. But I guess it's a big job to provide the necessary configuration..i.e. I have seen this construct in easylogging and we don't have a easylogging configuration yet.