Menu

cppcheck 2.19.1: error: Syntax Error: AST broken

2026-02-10
2026-02-11
  • Mike DeKoker

    Mike DeKoker - 2026-02-10

    Hello cppcheck folk,

    I have some C++20 code that is accused of containing a syntax error:

    template<std::uint16_t... Values>
    consteval auto make_flags() -> std::uint16_t
    { return (std::uint16_t{0} | ... | Values); }
    

    The above results in the following error:
    error: Syntax Error: AST broken, binary operator '|' doesn't have two operands. [internalAstError]

    Sample usage:

    #include <cstdint>
    
    template<std::uint16_t... Values>
    consteval auto make_flags() -> std::uint16_t
    { return (std::uint16_t{0} | ... | Values); }
    
    int main()
    {
        return make_flags<1,2,4>();
    }
    

    I suspect something isn't expecting the non-type template parameter. For the time being, I just gate the code with the preprocessor when cppcheck runs. Thanks for the awesome tool!

    Cheers,
    Mike.

     
  • CHR

    CHR - 2026-02-11

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

     

Log in to post a comment.

MongoDB Logo MongoDB