We're currently facing an issue with Cppcheck and typedefs, typedef enum to be more accurate.
We want to gather all typedefs in a C project for some coding rules of ours. Everything works as expected except enumerates because those, for some reason, are not listed within the "typedef-info" category in the result .dump files after parsing. But typedef structs are. This doesn't really make sense to us but maybe we misunderstood something ?
I've attached the header that we're parsing as a test.
The resulting .dumb <typedef-info> category can be found below : </typedef-info>
I don't have an update. Help would be appreciated.
Can you download cppcheck source code and compile+debug it.
debug cppcheck and set a breakpoint in Tokenizer::simplifyTypedef .. check if AB is added to mTypedefInfo .. if it isn't then please determine why it is not added.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Alright, got the source code, compiled it (had to remove RDYNAMIC content, otherwise not building on my MSYSTEM).
I think I found what was going on and why enums are not added by l1619 in simplifyTypedefCpp mTypedefInfo.push_back(std::move(typedefInfo));:
l1222 there's a check for an enumerate typedef to remove it from the current token processing. Meaning that if the token's type is an enum, it won't get added to mTypedefInfo. Looking at the "todo" comment, I'm assuming this is supposed to remove union typedef processing. Meaning instead of having this : if (Token::Match(tok->next(), "union %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
We're supposed to have this : if (Token::Match(tok->next(), "enum %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
By doing so, I indeed have enumerates inside the dump files appearing.
If I'm correct, how do you want to proceed ? Do you want to fix this yourself Daniel ? Or should I fork => pull request ?
Last edit: Nicolas harel 2023-11-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yeap, that's it. Had no other reference to communicate than line numbers so I had to resort to that . Although I did copy the line content, and technically it's still line 1222 even on github. I don't know how I can be more accurate than that.
Last edit: Nicolas harel 2023-11-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't got your feedback on this issue Daniel. Could this code snippet be the culprit ? As I said earlier changing this line seems to fix the problem but maybe I misunderstood its purpose.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
could you create a pull request please. I do think this line could be the culprit.. however when I read the code it says "enum" already so I don't follow what you have changed.
Last edit: Daniel Marjamäki 2023-11-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I understand the code (mostly by the todo comment just above), union typedef processing is not supported, and this part of the code is supposed to delete unions from the list as to not process them by the simplifyTypedefCpp. Hope this is clearer.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I understand the code (mostly by the todo comment just above), union typedef processing is not supported, and this part of the code is supposed to delete unions from the list as to not process them by the simplifyTypedefCpp. Hope this is clearer.
Ah ok then your suggestion sounds reasonable. Is it possible we unintentionally remove some enums by mistake now then..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
We're currently facing an issue with Cppcheck and typedefs, typedef enum to be more accurate.
We want to gather all typedefs in a C project for some coding rules of ours. Everything works as expected except enumerates because those, for some reason, are not listed within the "typedef-info" category in the result .dump files after parsing. But typedef structs are. This doesn't really make sense to us but maybe we misunderstood something ?
I've attached the header that we're parsing as a test.
The resulting .dumb <typedef-info> category can be found below : </typedef-info>
Cppcheck version : 2.10
Cmd call :
Thank you for your help =)
Last edit: Nicolas harel 2023-06-30
This should be fixed. There is no reason to leave out the enums as far as I remember.
I have created this ticket: https://trac.cppcheck.net/ticket/11807
Hello, any update on a potential a fix ? Can I help ?
I don't have an update. Help would be appreciated.
Can you download cppcheck source code and compile+debug it.
debug cppcheck and set a breakpoint in Tokenizer::simplifyTypedef .. check if AB is added to mTypedefInfo .. if it isn't then please determine why it is not added.
I will try my best and keep you updated on what I find.
Alright, got the source code, compiled it (had to remove RDYNAMIC content, otherwise not building on my MSYSTEM).
I think I found what was going on and why enums are not added by
l1619 in simplifyTypedefCpp mTypedefInfo.push_back(std::move(typedefInfo));:
l1222 there's a check for an enumerate typedef to remove it from the current token processing. Meaning that if the token's type is an enum, it won't get added to mTypedefInfo. Looking at the "todo" comment, I'm assuming this is supposed to remove union typedef processing. Meaning instead of having this :
if (Token::Match(tok->next(), "union %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
We're supposed to have this :
if (Token::Match(tok->next(), "enum %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
By doing so, I indeed have enumerates inside the dump files appearing.
If I'm correct, how do you want to proceed ? Do you want to fix this yourself Daniel ? Or should I fork => pull request ?
Last edit: Nicolas harel 2023-11-16
If you use latest cppcheck then the typedef info is added for your test code:
But the problem you point out probably still exists.
Line numbers can change at anytime, Cppcheck is actively developed.
Is it this code you talk about?
https://github.com/danmar/cppcheck/blob/e4730001/lib/tokenize.cpp#L1222
Yeap, that's it. Had no other reference to communicate than line numbers so I had to resort to that . Although I did copy the line content, and technically it's still line 1222 even on github. I don't know how I can be more accurate than that.
Last edit: Nicolas harel 2023-11-16
I haven't got your feedback on this issue Daniel. Could this code snippet be the culprit ? As I said earlier changing this line seems to fix the problem but maybe I misunderstood its purpose.
could you create a pull request please. I do think this line could be the culprit.. however when I read the code it says "enum" already so I don't follow what you have changed.
Last edit: Daniel Marjamäki 2023-11-27
Sure, no problem. Will do, as soon as I have a bit of time. I'm working on another project right now.
It should be "union" instead of "enum". My post was all wrong...
Instead of this :
We should have this :
As I understand the code (mostly by the todo comment just above), union typedef processing is not supported, and this part of the code is supposed to delete unions from the list as to not process them by the simplifyTypedefCpp. Hope this is clearer.
Ah ok then your suggestion sounds reasonable. Is it possible we unintentionally remove some enums by mistake now then..
PR has been opened, and happy holidays =)