Menu

False positive when [[noreturn]] is on destructor

2022-11-02
2022-11-07
  • Mark Bourgeault

    Mark Bourgeault - 2022-11-02

    The following code results in a containerOutOfBounds error in cppcheck 2.8.

    #include <iostream>
    #include <vector>
    #include <cstdlib>
    
    [[noreturn]] void fatal() { exit(1); }
    
    class FatalStream {
    public:
        [[noreturn]] ~FatalStream() { fatal(); }
    };
    
    int main() {
        std::vector<int> v;
        if (v.empty()) {
            FatalStream{};
        }
        std::cout << v[0] << '\n';
        return 0;
    }
    
     

    Last edit: Mark Bourgeault 2022-11-02
  • CHR

    CHR - 2022-11-07

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

     

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.