we are using CppCheck and the MISRA check in conjunction with IAR Workbench for ARM.
Include paths can be specified in the Project Settings, which is what we use.
Unfortunately the MISRA-Check does not take over these includes and so some defines are not known to it and it reports an error.
What is the best way to inform MISRA-Check about these include paths?
Greetings
Karsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Daniel,
thanks for your quick reply.
I have attached a sample file for you, which contains both the defines (starting at line 222) and the includes (starting at line 351). The .ewp file is a .xml file.
Kind regards
Karsten
ok thanks! for information, I do not have time to look at this in the near future. I wonder if you could look at it. I do not expect that it will be very difficult. And it would be good if you do it because you can test it on real projects also.
Here is similar code: https://github.com/danmar/cppcheck/blob/main/lib/importproject.cpp#L1067
You would need to write a corresponding function that will import the data from your ewp file.
Compiling cppcheck is easy. You just need a C++ compiler. There is no required dependency.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Daniel,
with version 9 of IAR Workbench it is possible to create a json-file directly from the project.
I tried to load it in cppcheck:
cppcheck.exe" --project="D:\compile_commands.json".
But unfortunately I get an error message that I can't do much with:
"type mismatch! call is<type>() before get<type>()" && is<std::string>()
Is the error in the json-file? How can I search for the cause?</std::string></type></type>
BestregardsKarsten
Last edit: Karsten Beck 2021-11-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes probably a bug in Cppcheck. Sounds like it expects that some value somewhere is a string and it's something else. I wonder if you volounteer to bisect it? you could remove some file entries from the json and see if it crashes.. or feel free to compile and trouble shoot..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After some time I got back to analyze the problem a bit.
Apparently the error is caused by the use of the square brackets ( "[" and "]"). As soon as they are used, the error "type mismatch! call is<type>() before get<type>()" && is<std::string>()" occurs.
Do you have another idea? I'm not that good at C#, unfortunately.</std::string></type></type>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That example is weird. I don't see a compile command. And there is no "file" field. Did you just extract this entry because Cppcheck has problems with this? And there are more entries that are "proper"?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello folks,
we are using CppCheck and the MISRA check in conjunction with IAR Workbench for ARM.
Include paths can be specified in the Project Settings, which is what we use.
Unfortunately the MISRA-Check does not take over these includes and so some defines are not known to it and it reports an error.
What is the best way to inform MISRA-Check about these include paths?
Greetings
Karsten
The best way would be to add a IAR Workbench project import into Cppcheck.
Do you have a small sample project with include paths and defines?
If it is possible to convert the IAR workbench project into a
compile_commands.json
then that can be imported into cppcheck directly.Hi Daniel,
thanks for your quick reply.
I have attached a sample file for you, which contains both the defines (starting at line 222) and the includes (starting at line 351). The .ewp file is a .xml file.
Kind regards
Karsten
ok thanks! for information, I do not have time to look at this in the near future. I wonder if you could look at it. I do not expect that it will be very difficult. And it would be good if you do it because you can test it on real projects also.
Here is similar code: https://github.com/danmar/cppcheck/blob/main/lib/importproject.cpp#L1067
You would need to write a corresponding function that will import the data from your ewp file.
Compiling cppcheck is easy. You just need a C++ compiler. There is no required dependency.
For your information I have created this trac ticket: https://trac.cppcheck.net/ticket/10428
Hey Daniel,
with version 9 of IAR Workbench it is possible to create a json-file directly from the project.
I tried to load it in cppcheck:
cppcheck.exe" --project="D:\compile_commands.json".
But unfortunately I get an error message that I can't do much with:
"type mismatch! call is<type>() before get<type>()" && is<std::string>()
Is the error in the json-file? How can I search for the cause?</std::string></type></type>
Last edit: Karsten Beck 2021-11-22
Very interesting!
maybe this can help:
https://jsonlint.com/
Valid JSON
Could it be an import error in Cppchecker after all?
Yes probably a bug in Cppcheck. Sounds like it expects that some value somewhere is a string and it's something else. I wonder if you volounteer to bisect it? you could remove some file entries from the json and see if it crashes.. or feel free to compile and trouble shoot..
After some time I got back to analyze the problem a bit.
Apparently the error is caused by the use of the square brackets ( "[" and "]"). As soon as they are used, the error "type mismatch! call is<type>() before get<type>()" && is<std::string>()" occurs.
Do you have another idea? I'm not that good at C#, unfortunately.</std::string></type></type>
It feels like that has been discussed and worked on not too long ago somewhere. either somewhere in this forum or there was a PR...
I guess I was thinking about this:
https://github.com/danmar/cppcheck/pull/3667
well not 100% the same but related. Can you show an example compile database that cppcheck has problems with.
Of course. Gladly.
@danielmarjamaki Could I help you with my example? How can we fix the error?
Last edit: Karsten Beck 2022-02-15
That example is weird. I don't see a compile command. And there is no "file" field. Did you just extract this entry because Cppcheck has problems with this? And there are more entries that are "proper"?
Yes, I did. I deleted always more to locate the error.
ok thanks for explanation. that is good.
I have pushed a possible fix:
https://github.com/danmar/cppcheck/commit/c968aeaf73d4b1767e6886200baca31c3341a3f3
Can you try it out? For information there is a nightly build here:
https://github.com/danmar/cppcheck/actions/workflows/release-windows.yml
The fix will be provided in build 684.
Ok, I saw what build 684 was built tonight. I may be obviously blind, but where can I download this build as an installfile?
https://github.com/danmar/cppcheck/actions/workflows/release-windows.yml
You must be logged in to download the installer.
Ahhh, I am a goofball ;-)
@danielmarjamaki I have just installed the build 684 and tried it with it: the JSON file can now be read successfully.
So far first THANK YOU!
If you manage to convert the project into a
compile_commands.json
it seems that solution should be mentioned here: https://stackoverflow.com/questions/58353422/how-to-convert-iar-ewp-to-lsp-compile-commands-json-databaseFor information, if your company would be interested to pay for development of this feature let me know.
I will ask about it, but unfortunately do not have much hope.