Menu

Syntax Error: AST broken, 'foo' doesn't have a parent.

2024-09-04
2024-09-04
  • Sebastian Weiser

    When I check this in C++ on Windows, I get a weird error message:

    #include <atlstr.h>
    
    int _tmain(int argc, _TCHAR* argv[]) 
    {
        CString foo;
    
        memset((void*)LPCTSTR(foo), 0, foo.GetLength());
    
        return 0;
    }
    

    cppcheck.exe" --library=windows --platform=win32A --language=c++ cppcheck-ast.c
    Checking cppcheck-ast.c ...
    cppcheck-ast.c:7:36: error: Syntax Error: AST broken, 'foo' doesn't have a parent. [internalAstError]
    memset((void*)LPCTSTR(foo), 0, foo.GetLength());
    ^

    It only happens with exactly those parameters (library, platform and language).
    In the code, the error only occurs if "foo" is used twice in the parameter list. If either the pointer or the length are given without using "foo", no error occurs.

     
  • CHR

    CHR - 2024-09-04

    LPCTSTR gets replaced with const char*, which leads to invalid code in the example.
    Added this example to https://trac.cppcheck.net/ticket/11430

     

    Last edit: CHR 2024-09-07

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.