Menu

"variable = variable = value" -> should issue a warning

2019-09-12
2020-08-18
  • Sven Strickroth

    Sven Strickroth - 2019-09-12

    In a codebase I've spotted variable assignments in the form of "variable = variable = value" (e.g., "m_bA = m_bA = 2;"). It would be nice if cppcheck would also detect such double assignments.

     
  • Daniel Marjamäki

    Could you elaborate a little.

    int x;
    
    void f() {
         x = x = 2;
    }
    

    Cppcheck output:

    $ ./cppcheck --enable=style 1.c
    Checking 1.c ...
    1.c:5:5: warning: Redundant assignment of 'x' to itself. [selfAssignment]
      x = x = 2;
        ^
    
     
  • Sven Strickroth

    Sven Strickroth - 2019-09-12

    These cases (https://gitlab.com/tortoisegit/tortoisegit/commit/9051ad7a35165f2f45ecdcc2220c914998a655de) were not spotted by cppcheck (GUI).

     
  • Daniel Marjamäki

    hmm... I do not get these warnings neither... I think this is a real problem in Cppcheck. Thanks!

     
  • Daniel Marjamäki

    The first false negative seems to be related to the BEGIN_MESSAGE_MAP ... END_MESSAGE_MAP

    Cppcheck does not know what that is.. and it is not defined anywhere in the repo.

    hmm.. .you are supposed to get a information message if there is such unknown macro! So you can fix it in some way.

    I have created this ticket:
    https://trac.cppcheck.net/ticket/9354

     
  • versat

    versat - 2019-09-18

    @Sven The ticket http://trac.cppcheck.net/ticket/9354 has been resolved.
    The unknown macros will now be reported and there is now a configuration for the MFC (mfc.cfg).
    I have added another configuration for the Microsoft ATL (microsoft_atl.cfg) since Cppcheck found corresponding macros that were also missing a configuration for analyzing TortoiseGit.
    Several false positives and other issues found by analyzing TortoiseGit were also fixed in the Windows configuration of Cppcheck.
    So the results should be a bit better now.

    BTW: I love TortoiseGit and use it very often. Thanks for such a great tool.

     
  • Allan Braun

    Allan Braun - 2020-02-16

    Where can I download mfc.cfg

     
  • Allan Braun

    Allan Braun - 2020-05-14

    I just installed the latest version 2.0
    For a MS-Windows Visual Studio project
    I still get the error
    There is an unknown macro here somewhere. Configuration is required. If BEGIN_MESSAGE_MAP is a macro then please configure it.

     
  • Allan Braun

    Allan Braun - 2020-06-21

    I just installed version 2.1
    Still same problem
    How do I work around this?

     
  • Daniel Marjamäki

    You asked how to download mfc.cfg. Sorry that I did not reply. If you still wonder; feel free to download this file: https://github.com/danmar/cppcheck/raw/2.1/cfg/mfc.cfg

    all cfg files:
    https://github.com/danmar/cppcheck/tree/2.1/cfg

    I believe the intention is to distribute all of the cfg files except "cppcheck-internal.cfg". So we need to review this.

     
  • Daniel Marjamäki

    I checked the tortoisegit code and it seems we have a couple of problems. With the mfc.cfg I do not get unknown macro warnings about BEGIN_MESSAGE_MAP but I do see other problems that we should fix in Cppcheck.

     
  • Allan Braun

    Allan Braun - 2020-06-27

    Hi Daniel
    I got the mfc.cfg
    How do I load this file?
    I am using the GUI

     
  • Daniel Marjamäki

    if you put a cfg file in the same folder as your <foo>.cppcheck project file then it should be shown in the list in the GUI.

     
  • Daniel Marjamäki

    please see the list in the project file dialog.

     

Log in to post a comment.