Menu

FP: internalAstError

2022-12-20
2022-12-21
  • Muhammad Javed

    Muhammad Javed - 2022-12-20

    I have the following scenario:

    // test.cpp
    #include <array>
    
    template<typename T>
    inline constexpr std::array<T, 1> cArray = std::array<T, 1>({T()});
    
    template<typename T>
    void foo(const T& aValue)
    {
        if (cArray<T>[0] <= aValue)
        {
            return;
        }
    }
    

    In this scenario I have a templated constant that evaluates to an std::array. Performing a comparison against the contents of the std::array results in an internalAstError. Here are the cppcheck results:

    Checking test.cpp ...
    test.cpp:15:8: error: Syntax Error: AST broken, 'if' doesn't have two operands. [internalAstError]
        if (cArray<T>[0] <= aValue)
    

    Storing the comparison in a bool results in this error:

    Checking test.cpp ...
    test.cpp:10:10: error: Uninitialized variable: comparison [legacyUninitvar]
        bool comparison = (cArray<T>[0] <= aValue);
    

    It looks like cppcheck may be having trouble with a templated variable that evaluates to an std::array? I hope this information helps, thanks!

    EDIT: Posted faulty code on accident, however it should be fixed now

     

    Last edit: Muhammad Javed 2022-12-20
  • CHR

    CHR - 2022-12-21

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

     
  • Muhammad Javed

    Muhammad Javed - 2022-12-21

    Thank you so much!

     

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.