Menu

How does -U -D and --force work together

Sonni
2021-02-05
2021-02-08
  • Sonni

    Sonni - 2021-02-05

    When I have defined both -U, -D and --force arguments it looks like cppcheck still performs some og the combinations of defines that are undefined with the -U argument.

    How does these 3 arguments interact ?

     
  • Daniel Marjamäki

    Example code with three bugs (when x,y,z is assigned).

    #ifdef A
      x=100/0;
      #ifdef B
        y=100/0;
      #endif
    #else
      z=100/0;
    #endif
    

    Configurations tested:
    cppcheck test.c => "", "A", "A;B" => all bugs are found
    cppcheck -DA test.c => "A" => The first bug is found
    cppcheck -UA test.c => "" => The last bug is found
    cppcheck --force -DA test.c => "A", "A;B" => The two first bugs are found

    I guess we should clarify the manual somehow. http://cppcheck.sourceforge.net/manual.html#preprocessor-settings

    Do you have some pointer about how we could clarify it.

     

    Last edit: Daniel Marjamäki 2021-02-06
  • Sonni

    Sonni - 2021-02-08

    It seams to work. I had created the .cppcheck project file by hand and it had an error in the <undefine> tag, which explains why I went through all combinations with the undefined flags.</undefine>

    I made a smalle test aswell:
    
    #ifdef A1
    int a1=100/0;
    #ifdef A2
    int a2=100/0;
    #endif
    #endif
    
    #ifdef B1
    int b1=100/0;
    #ifdef B2
    int b2=100/0;
    #endif
    #endif
    
    #ifdef C1
    int c1=100/0;
    #ifdef C2
    int c2=100/0;
    #endif
    #endif
    

    and with different define/undefine's set I get the expected behavior.

    For the documentation the key point must be: All flags set with define/-D and undefine/-U will be fixed, all other flags will be tried in combinations when the --force argument is specified.

     
  • Daniel Marjamäki

    For the documentation the key point must be: All flags set with define/-D and undefine/-U will be fixed, all other flags will be tried in combinations when the --force argument is specified.

    Yes that is a good point thanks 👍

     

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.