Menu

cppcheck does not handle #line statements generated by Bison well

2021-11-05
2021-11-06
  • david ingamells

    david ingamells - 2021-11-05

    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

    <error id="noExplicitConstructor" severity="style" msg="Class &apos;FilterParser&apos; has a constructor with 1 argument that is not explicit." verbose="Class &apos;FilterParser&apos; 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">
        <location file="/ 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
    • Daniel Marjamäki

      strange bug. Thanks!

       

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.