Menu

internalAstError when using multiple requires-expressions with parameters in a concept

5 days ago
4 days ago
  • itzexpoexpo

    itzexpoexpo - 5 days ago

    Cppcheck 2.20.0 flags this code:

    template <typename test_t>
    concept MRE = requires() { std::is_aggregate_v<test_t>; } || requires() { std::is_standard_layout_v<test_t>; };
    

    with the following error:

    test.cpp:5:59: error: Syntax Error: AST broken, binary operator '||' doesn't have two operands. [internalAstError]
    concept MRE = requires() { std::is_aggregate_v<test_t>; } || requires() { std::is_standard_layout_v<test_t>; };
    

    this error occurs only if a parameter list is present (empty or otherwise), it does not occur in:

    template <typename test_t>
    concept MRE = requires { std::is_aggregate_v<test_t>; } || requires { std::is_standard_layout_v<test_t>; };
    

    or if the requires expressions are used in any other context beside the constraint expression of a concept:

    struct Test;
    
    static_assert(
        requires() { std::is_aggregate_v<Test>; } || requires() { std::is_standard_layout_v<Test>; }
    );
    
    if constexpr(requires() { std::is_aggregate_v<Test>; } || requires() { std::is_standard_layout_v<Test>; }) {}
    
    template <typename test_t>
        requires requires() { std::is_aggregate_v<test_t>; } || requires() { std::is_standard_layout_v<test_t>; }
    void myTestFn()
    {}
    

    the actual requirements in the expressions don't matter, I just chose something to make it small and reproducible.

     
  • CHR

    CHR - 4 days ago

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

     

Log in to post a comment.

MongoDB Logo MongoDB