Menu ▾ ▴

false positive, syntaxError, function try block with override keyword

2026-10-21
2026-10-22
  • Joel Shuman

    Joel Shuman - 2026-10-21

    Hello,
    We ran into a corner-case false-positive syntaxError I'd like to report. It is similar to this which was fixed long ago.

    In this corner-case, using the override keyword causes the false positive.

    struct base {
        virtual ~base() = default;
    
        virtual void foo()
        try {} catch (...) {};
    };
    
    struct special : base {
        void foo() override // This override causes the try on the next line to false fail.
        try {} catch (...) {}
    };
    
    int main() {
        special s;
        s.foo();
        return 0;
    }
    

    I am testing with cppcheck 2.22.0.

    Here is the exact error: syntax error: keyword 'try' is not allowed in class/struct/union/enum scope [syntaxError]

     
  • Joel Shuman

    Joel Shuman - 2026-10-21

    I also should mention that cppcheck 2.19.0 did not have this false positive.

     
  • CHR

    CHR - 2026-10-22

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

     

Log in to post a comment.