Menu

False positive: returns in lambda functions [knownConditionTrueFalse]

2020-06-29
2021-01-26
  • Stefan Löffler

    Stefan Löffler - 2020-06-29

    The code

    int main(int argc, char * argv[]) {
        const int a = [=]() {
            if (argc < 1) {
                return 0;
            }
            return 1;
        }();
    
        if (argc < 1) {
            return 1;
        }
        return 5*a;
    }
    

    produces

    lambda-return.cpp:9:11: style: Condition 'argc<1' is always false [knownConditionTrueFalse]
     if (argc < 1) {
              ^
    lambda-return.cpp:3:12: note: Assuming condition 'argc<1' is false
      if (argc < 1) {
               ^
    lambda-return.cpp:9:11: note: Condition 'argc<1' is always false
     if (argc < 1) {
              ^
    
     
  • CHR

    CHR - 2021-01-25

    This reproduces for me in v2.3.

     
  • Daniel Marjamäki

    Thanks! I can reproduce with cppcheck 2.3 but not with latest head. I think it has been fixed.

     

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.