Menu

False positive: returnDanglingLifetime

2023-04-13
2023-04-14
  • Mark Ridgewell

    Mark Ridgewell - 2023-04-13

    Minimal repro attached. Output:

    $ cppcheck --enable=warning --platform=native Matrix.cpp
    Checking Matrix.cpp ...
    Matrix.cpp:52:12: error: Returning object that will be invalid when returning. [returnDanglingLifetime]
        return {
               ^
    Matrix.cpp:56:9: note: Passed to constructor of 'Matrix'.
            {0, 0, 0, T{1}},
            ^
    Matrix.cpp:52:12: note: Returning object that will be invalid when returning.
        return {
               ^
    

    This is a false positive as all objects are passed to the constructor by value and are copied.

     
  • CHR

    CHR - 2023-04-14

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11666

     

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.