• freely
    link
    fedilink
    arrow-up
    1
    ·
    3 years ago

    GCC’s sanitizers actually catches most of these. The only one it wont complain about is

    #include <optional>
    
    int f() {
        std::optional<int> x(std::nullopt);
        return *x;
    }
    

    because nullopt is a nullopt_t which is akin to NULL, and will read as 0 if you try to do something with it, as far as I can tell…

    The span missing bounds checking isn’t a huge deal, but I guess it would make sense for them to add an at method like most other containers have…

    TLDR: Use g++ -Werror -Wpedantic -Wall -fsanitize=address,undefined,null when compiling. Maybe do another run with thread, leak, or other sanitizers if needed.