I ran into autocode that has a curious use of braces in the constructor that causes an internalAstError. I recreated the issue below.
// file CppcheckCtorDefinitionError.cpp#include<cstdint>typedefstd::uint8_tUInt8;typedefstd::uint32_tUInt32;structThingWithPath{ThingWithPath();UInt8*pFilePath;UInt32filePathElements;};ThingWithPath::ThingWithPath():pFilePath{newUInt8[512]{}},// the error occurs here with the empty "{}"filePathElements{0}{}intmain(){ThingWithPatht;return0;}
<?xml version="1.0" encoding="UTF-8"?><resultsversion="2"><cppcheckversion="2.10"/><errors><errorid="internalAstError"severity="error"msg="Syntax error. Unexpected tokens in initializer."verbose="Syntax error. Unexpected tokens in initializer."file0="CppcheckCtorDefinitionError.cpp"><locationfile="CppcheckCtorDefinitionError.cpp"line="14"column="29"/></error><errorid="missingIncludeSystem"severity="information"msg="Cppcheck cannot find all the include files (use --check-config for details)"verbose="Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project's include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config."/></errors></results>
The second error might be hinting at a configuration issue on my machine. Running on WSL2.0 (particularly, 5.15.90.1-microsoft-standard-WSL2). Used Ubuntu 10.3.0-1ubuntu1~20.04 to build cppcheck. I confirmed the error did not occur on cppcheck 2.9, and the older version also caught the unused variable in main.
I confirmed that the code compiled for C++11, 14, 17.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I ran into autocode that has a curious use of braces in the constructor that causes an
internalAstError
. I recreated the issue below.Command run:
cppcheck --enable=all --inline-suppr --xml CppcheckCtorDefinitionError.cpp
XML prints the following.
The second error might be hinting at a configuration issue on my machine. Running on WSL2.0 (particularly,
5.15.90.1-microsoft-standard-WSL2
). UsedUbuntu 10.3.0-1ubuntu1~20.04
to build cppcheck. I confirmed the error did not occur oncppcheck 2.9
, and the older version also caught the unused variable in main.I confirmed that the code compiled for C++11, 14, 17.
Thanks for reporting, I have added your example here: https://trac.cppcheck.net/ticket/11378#comment:16