Menu

CppCheck Syntax Error: AST Broken

2021-09-15
2021-09-17
  • Martin Brieg

    Martin Brieg - 2021-09-15

    Dear all,

    Cppcheck seems to not understand the code below:

    include <iostream></iostream>

    include <type_traits></type_traits>

    // Same as std::is_same_v, but can be one of multiple options
    template <class t,="" class...="" rest="">
    inline constexpr bool is_one_of_v = (std::is_same_v<t, rest=""> || ...);</t,></class>

    int main()
    {
    std::cout << "Hello World!\n";
    return is_one_of_v<double, int,="" size_t,="" double="">;
    }</double,>

    When trying to parse it, cppcheck produces the following error and stops analyzing the code:
    Syntax Error: AST broken, binary operator '=' doesn't have two operands. [id: internalAstError]

    I would welcome a fix, since a header with this code is included very often in our solution and therefore renders cppcheck useless.

    Best Regards,
    Martin Brieg

    PTV GROUP
    Software Developement Microscopic Simulation
    Haid-und-Neu-Str. 15, 76131 Karlsruhe, Germany

    Phone +49 (0) 721 9651-7234

    martin.brieg@ptvgroup.com
    www.ptvgroup.com

    --
    Explore the PTV Group in 2 minutes!http://www.youtube.com/watch?v=axifxOS_mFI&feature=youtu.be
    Register for the PTV-Newsletterhttp://company.ptvgroup.com/de/news-presse/newsletter/newsletter-abonnement/

    Follow us on social media:
    Linkedinhttp://ptv.to/linkedin
    Twitterhttp://ptv.to/twitter
    Xinghttp://ptv.to/xing
    Instagramhttps://www.instagram.com/mindofmovement/?hl=de
    Facebookhttp://ptv.to/facebook
    --
    PTV Planung Transport Verkehr AG
    Headquarters: Karlsruhe
    Executive Board: Christian U. Haas (CEO), Klaus Lechner, Dr. Peter Overmann
    ​Supervisory Board: Dr. Manfred Döss, Martin Korbmacher
    Commercial Register (HRB‑Nr): 109262
    Local Court: Mannheim

     
  • CHR

    CHR - 2021-09-15

    I can't reproduce your problem with current head using the code below:

    #include <iostream>
    #include <type_traits>
    // Same as std::is_same_v, but can be one of multiple options
    template <class t, class... rest>
    inline constexpr bool is_one_of_v = (std::is_same_v<t, rest> || ...);
    
    int main()
    {
    std::cout << "Hello World!\n";
    return is_one_of_v<double, int, size_t, double>;
    }
    
     
  • Martin Brieg

    Martin Brieg - 2021-09-17

    To me, this happens all the time. I am running on Windows using CppCheck 2.5installer.

    > cppcheck --version
    Cppcheck 2.5
    > cppcheck --enable=warning,style,performance --std=c++17 --language=c++ --inconclusive --library=std --library=windows .\ConsoleApplication3.cpp
    Checking ConsoleApplication3.cpp ...
    ConsoleApplication3.cpp:5:35: error: Syntax Error: AST broken, binary operator '=' doesn't have two operands. [internalAstError]
    inline constexpr bool is_one_of_v = (std::is_same_v<t, rest> || ...);
                                      ^
    > type .\ConsoleApplication3.cpp
    #include <iostream>
    #include <type_traits>
    // Same as std::is_same_v, but can be one of multiple options
    template <class t, class... rest>
    inline constexpr bool is_one_of_v = (std::is_same_v<t, rest> || ...);
    
    int main()
    {
      std::cout << "Hello World!\n";
      return is_one_of_v<double, int, size_t, double>;
    }
    PS C:\Users\bri\source\repos\ConsoleApplication3>
    
     
  • Martin Brieg

    Martin Brieg - 2021-09-17

    Ah, yes. Head works fine. Sorry for not reading your answer correctly. I will use the current build for testing purposes. Thanks for fixing it!

     

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.