Menu

Unexpected behaviour with the -U option

Gildas
2020-12-10
2021-01-06
  • Gildas

    Gildas - 2020-12-10

    I think there is a unexpected behaviour with the -U option

    Take the sample code below, ugly, isn't it... :) So this code overrides the metasyntaxicvariable in an #ifdef, that will run to a redundantInitialization warning if the DEFINE is available

    #include <QCoreApplication>
    #include <QDebug>
    #include <QObject>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QString metasyntaxicvariable = QObject::tr("john doe");
        #ifdef MY_SUPER_DEFINE_TO_OVERRIDE
        // cppcheck-suppress redundantInitialization
        metasyntaxicvariable = QObject::tr("toto in french");
        #endif
        qDebug() << metasyntaxicvariable;
    
        return a.exec();
    }
    

    He is what i try and what are the results :
    - remove the cppcheck-suppress redundantInitialization from the code above
    - run cppcheck with the -DMY_SUPER_DEFINE_TO_OVERRIDE => ok, redundantInitialization warning is detected
    - put back in place the cppcheck-suppress redundantInitialization line like above
    - run cppcheck without the -DMY_SUPER_DEFINE_TO_OVERRIDE => ok, no warning as there is no override
    - now run cppcheck by specifying we did not want that define with the -UMY_SUPER_DEFINE_TO_OVERRIDE => NOT OK, a new warning appears for an unmatchedSuppression (main.cpp 12 unmatchedSuppression Unmatched suppression: redundantInitialization)

    For me, with -U option, we shouldn't have a warning...

     
  • Gildas

    Gildas - 2021-01-04

    can this topic be created with the content of the found bug ? the "Post awaiting moderation." since 2020-12-10... :/

     

    Last edit: Gildas 2021-01-04
  • Daniel Marjamäki

    hi sorry we did not respond earlier. thanks for pinging us..

     
  • Daniel Marjamäki

    I believe this is a duplicate of https://trac.cppcheck.net/ticket/5704

     
  • Gildas

    Gildas - 2021-01-06

    Yes, i haven't find it when i search ! Sorry for the duplicate...

    You have a good memory, the ticket has 7 years !! :D

    As it has 7 years, i don't think it'll be resolved in the future... :/

    Thanks for your work on this project !!!

     
  • Daniel Marjamäki

    I look through all defects now and then and try to fix old problems. Unfortunately this one feels rather tricky to fix.

     

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.