Hi,
I am running cppcheck 2.5 on a project that generates a c++ source file using GNU Bison and am using the cmake generated project file to tell it the files to analyse. This project file includes the bison generated source file, so cppcheck runs on that C++ file too.
The result is that it generates an issue
<errorid="noExplicitConstructor"severity="style"msg="Class 'FilterParser' has a constructor with 1 argument that is not explicit."verbose="Class 'FilterParser' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided."cwe="398"file0="/volumes1/david.ingamells/projects/CTA-1175/test/Global_MSGeneralpp/trunk/src/Attribute/Filter.cpp"><locationfile="/ lalr1.cc:37"line="561"column="5"/><symbol>FilterParser</symbol></error>
notice the name of the file in the location record "/ lalr1.cc:37"
Examining the C++ file itself, which actually has the name "[workdir]/Attribute/parser/generatedFilterBison.cpp" the following lines are relevant
// A Bison parser, made by GNU Bison 3.0.4.
...
#line 10 "<mypath>/Attribute/parser/FilterParser.y" // lalr1.cc:377
...
it looks to me as if cppcheck is somehow using the comment on the "#line" line, ignoring the quoted string and removing the leading and trailing character from the end of the line ("// lalr1.cc:377") to get to "/ lalr1.cc:37"
Given that the file in question is generated by GNU Bison and is listed in a file generated by cmake, it is difficult to workaround this.
Can this be fixed to use the proper file name from the "#line" statement please, maybe first by stripping any comments from the line?
thanks,
David
Last edit: david ingamells 2021-11-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am running cppcheck 2.5 on a project that generates a c++ source file using GNU Bison and am using the cmake generated project file to tell it the files to analyse. This project file includes the bison generated source file, so cppcheck runs on that C++ file too.
The result is that it generates an issue
notice the name of the file in the location record "/ lalr1.cc:37"
Examining the C++ file itself, which actually has the name "[workdir]/Attribute/parser/generatedFilterBison.cpp" the following lines are relevant
it looks to me as if cppcheck is somehow using the comment on the "#line" line, ignoring the quoted string and removing the leading and trailing character from the end of the line ("// lalr1.cc:377") to get to "/ lalr1.cc:37"
Given that the file in question is generated by GNU Bison and is listed in a file generated by cmake, it is difficult to workaround this.
Can this be fixed to use the proper file name from the "#line" statement please, maybe first by stripping any comments from the line?
thanks,
David
Last edit: david ingamells 2021-11-05
strange bug. Thanks!
Fixed by https://github.com/danmar/simplecpp/commit/139c660ed9f3b111061a25305a5f8597cfa3212b
I will update simplecpp in cppcheck sometime before next release.