Menu

Adding c++ language elements to .cfg file

SAT
2019-08-19
2019-08-21
  • SAT

    SAT - 2019-08-19

    Hi everyone,

    I'm trying to use cppcheck with some large libs. For this, writing a custom .cfg file generally works for me.
    But three questions remain, that I could resolve neither with the included .cfg files nor with the PDF doc.

    I created a fictitious code snipped to illustrate the points:

    namespace garden {
        enum fruit {
            apple = 0,
            grape,
            orange,
            pear
         };
    
         class tool {
           //a lot of functions in here that I don't need externally
           }
    
         class openwork {
         ...
           public:
             std:string operator | (const openwork&) const;
         }
    }
    
    1. Enum: How can I declare the type "garden::fruit" in the cfg file?
    2. Class without specifying implementations: How do I declare the class "garden::tool" in a cfg file?
    3. Operators: What is the syntax for overloaded operators in a class? '|' in "garden::openwork"

    If not defined in the cfg file, all the cases lead to "--check-library: There is no matching configuration for function ...", when a function in the scanned code takes the unknown enum, class, calculation result as parameter.

    Regards,
    Tim

     
  • versat

    versat - 2019-08-20

    Hi,

    1. It is not yet possible to configure enums via the library configuration.
      There is a feature request for this: https://trac.cppcheck.net/ticket/8183
      As a workaround you can simply copy the enum to a header file and let Cppcheck include it before everything else via the --include= option.

    2. It is not yet possible to configure classes in the library files. I have created a feature request for this: https://trac.cppcheck.net/ticket/9031
      As a workaround you can for example forward declare such a class in a header file that is included first (see 1.).

    3. AFAIK it is not possible to configure overloaded operators in the configuration. I guess this is a special case. Maybe we should create a ticket with a feature request for this too.

    Regards

     
  • SAT

    SAT - 2019-08-21

    Hi versat,

    Thanks for the reply.
    Good, that the points are already beeing tracked - bad that the enum feature is open already for two years.

    I made a work-around with a the following declarations for 1. This comes close for the behavior, but its not exactly the same (size of the type).

    <podtype name="garden::fruit" sign="u" size="8"/>
      <define name="apple" value="0"/>
      <define name="grape" value="1"/>
      <define name="orange" value="2"/>
      <define name="pear" value="3"/>
    

    For the class declerations (2.) I don't see an easy work-around, so ticket #9031 gets a push from my side.

    Regards
    Tim

     

    Last edit: SAT 2019-08-21

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.