Menu

C typedef enum not in <typedef-info> in .dumb file after parsing

2023-06-30
2023-12-20
  • Nicolas harel

    Nicolas harel - 2023-06-30

    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>

    <typedef-info>
        <info name="Books" file="C:/xxx/test_header.h" line="20" column="3" used="0"/>
    </typedef-info>
    

    Cppcheck version : 2.10
    Cmd call :

    cppcheck.exe --enable=all -j 4 --xml --dump "C:/xxx/test_header.h"
    

    Thank you for your help =)

     

    Last edit: Nicolas harel 2023-06-30
  • Daniel Marjamäki

    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

     
    👍
    1
  • Nicolas harel

    Nicolas harel - 2023-10-12

    Hello, any update on a potential a fix ? Can I help ?

     
    • Daniel Marjamäki

      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.

       
      • Nicolas harel

        Nicolas harel - 2023-10-13

        I will try my best and keep you updated on what I find.

         
  • Nicolas harel

    Nicolas harel - 2023-11-16

    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
    • Daniel Marjamäki

      If you use latest cppcheck then the typedef info is added for your test code:

        <typedef-info>
          <info name="Books" file="e1.c" line="11" column="1" used="0"/>
          <info name="hello_enum" file="e1.c" line="1" column="1" used="0"/>
        </typedef-info>
      

      But the problem you point out probably still exists.

      l1222 there's a check for an enumerate typedef to remove it from the current token processing.

      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

       
      • Nicolas harel

        Nicolas harel - 2023-11-16

        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
  • Nicolas harel

    Nicolas harel - 2023-11-27

    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.

     
    • Daniel Marjamäki

      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
      • Nicolas harel

        Nicolas harel - 2023-11-28

        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 :

        if (Token::Match(tok->next(), "enum %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
        

        We should have this :

        if (Token::Match(tok->next(), "union %type% %type% ;") && tok->strAt(2) == tok->strAt(3))
        

        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.

         
  • Daniel Marjamäki

    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..

     
  • Nicolas harel

    Nicolas harel - 2023-12-20

    PR has been opened, and happy holidays =)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.