Menu

cppcheck 2.11: false positive CastIntegerToAddressAtReturn with C++20 templated lambda

2023-06-27
2023-06-27
  • Sylvain Joubert

    Sylvain Joubert - 2023-06-27

    Updgrading to cppcheck 2.11 I know get CastIntegerToAddressAtReturn warnings on the following test code reduced from my codebase:

    int* nested_template_lambda_return()
    {
      auto explicitTemplate = []<typename T>()
      {
        return true;
      };
    
      auto noTemplate = []()
      {
        return true;
      };
    
      return nullptr;
    }
    
    $ cppcheck test.cpp --enable=portability
    Checking test.cpp ...
    test.cpp:5:5: portability: Returning an integer in a function with pointer return type is not portable. [CastIntegerToAddressAtReturn]
        return true;
        ^
    

    This only happens with explicit template specification on lambdas. cppcheck 2.10 was fine with that code so far.

     
  • CHR

    CHR - 2023-06-27

    Thanks for reporting, please see https://trac.cppcheck.net/ticket/11275

     

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.