Menu

latest cppcheck: new syntax error (AST broken)

Martin
2022-01-17
2022-03-02
  • Martin

    Martin - 2022-01-17

    Hi all.

    there's a new syntax error occurring with cppcheck head.
    With 7406dd8c941a60ba111dd4857dce0b99c54eef79 it appeared.
    With 12abf85d1d63e87edfeab8533e025ee7aec45a89 it wasn't there.

    Example code is:

    auto createArgv(const std::vector<std::string> &arguments) -> std::unique_ptr<const char *[]>
    {
       auto argv = cpp14::make_unique<const char *[]>(arguments.size() + 1);
       for (decltype(arguments.size()) i = 0; i < arguments.size(); ++i)
       {
          argv[i] = arguments[i].c_str();
       }
    }
    

    cppcheck output is:

    /foo.cpp:4:18: error: Syntax Error: AST broken, 'arguments' doesn't have a parent. [internalAstError]
       for (decltype(arguments.size()) i = 0; i < arguments.size(); ++i)
                     ^
    

    Could you please check?

    Thanks,
    Martin

     
  • CHR

    CHR - 2022-01-17

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

     
  • Martin

    Martin - 2022-01-18

    Same goes for:

    void foo(Bar& bar)
    {
       const auto baz = [](const decltype(bar.p1)::value_type& p2) {
          return 0;
       };
    }
    

    cppcheck says:

    /foo.cpp:3:39: error: Syntax Error: AST broken, 'bar' doesn't have a parent. [internalAstError]
       const auto baz = [](const decltype(bar.p1)::value_type& p2) {
                                          ^
    
     
  • Anssi Kolehmainen

    Ran probably into same issue with cppcheck 2.7 and uthash.h

    #include "uthash.h"
    struct a { UT_hash_handle hh; };
    struct b { struct a *hash; };
    
    void test() {
      struct b *c = calloc(1, sizeof(struct b));
      struct a *xx = calloc(1, sizeof(struct a));
    
      // Works
      HASH_DEL(xx, xx);
    
      // internalAstError
      HASH_DEL(c->hash, xx);
    }
    

    gcc -E version in https://gist.github.com/Aketzu/9da9266bc33ac5829f7d41910c7fb138

     
    • CHR

      CHR - 2022-02-28

      Reduced example:

      struct A;
      struct B {
        A* hash;
      };
      
      void f(void* p, B* b) {
          b->hash = (__typeof(b->hash))(p);   
      }
      

      internalAstError is reported for __typeof, __typeof__, typeof, decltype

       
  • Paul Fultz

    Paul Fultz - 2022-03-02

    It also fails for any function call, like this:

    struct A;
    struct B {
      A* hash;
    };
    auto g(A* a) {
      return [=](void*) { return a; };
    }
    void f(void* p, B* b) {
        b->hash = (g(b->hash))(p);   
    }
    

    We should probably file a ticket for this.

     
  • CHR

    CHR - 2022-03-02
     

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.