Menu

internalAstError with complex "using"

2022-12-09
2022-12-12
  • Andrey Alekseenko

    The following code is happily accepted by g++-10 and clang++-15, yet cannot be parsed by cppcheck.

    It seems that float_ptr(b.data()) is interpreted as float * (b.data()), which is indeed incorrect, because float_ptr should be treated as a single token. Rewriting the offending statement as (float_ptr)(b.data()) solves the problem.

    struct B {
      float *data() const;
    };
    
    namespace n {
    bool N(float *v);
    }
    
    bool c(B &b) {
      using float_ptr = float *;
      return n::N(float_ptr(b.data()));
    }
    
    $ ./bin/cppcheck internalAstError.cpp 
    Checking internalAstError.cpp ...
    internalAstError.cpp:11:25: error: Syntax Error: AST broken, 'b' doesn't have a parent. [internalAstError]
      return n::N(float_ptr(b.data()));
                            ^
    
     
  • CHR

    CHR - 2022-12-12

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

     

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.