make cppcheck skip the PACKAGE definition

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:58:03

问题


I'm using the GUI version of cppcheck 1.64 for static code analysis on C++-Builde-6 code. For DLL exports and imports, the definition of PACKAGE is necessary:

/// A dialog exported from a BPL (a VCL-specific kind of DLL)
class PACKAGE MySharedDialog {

public:
    // lots of methods to-be checked

private:
    // lots of methods to-be checked

    // lots of members

};

Cppcheck stops when it encounters PACKAGE because it doesn't know what it means:

The code 'class PACKAGE TAppInfoDialog {' is not handled. You can use -I or --include to add handling of this code.

...and this of course means that the entire class isn't checked. If I could make cppcheck simply ignore the PACKAGE "keyword", it would do exactly the right thing, but how to do it? Including its original definition via include path, seems to be not an option: cppcheck then tells me a lot about headers of the VCL framework I cannot change...

The manual does not describe an option to do it, Google doesn't help, SO does not have an answer yet.

In the cppcheck issue tracker, I found the analogous problem #4707 (Microsoft 'abstract' and 'sealed' extension for class) – cppcheck. Here the lead developer suggests to create a file and (pre-?)include it to the cppcheck run, but I'm using the GUI version and there is no option to include a single file. So I tried to add a directors to the include section of my project options (an XML file), then I edited the corresponding line to a file specification, but that's clearly nonsense, because this section contains include paths.

What can I try next?


回答1:


A solution is to add the definition of PACKAGE (being empty) to the project file:

<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
    <defines>
        <define name="PACKAGE=" />
    </defines>    
</project>

This solution I finally found in this small but valuable project file description at the project repo cppcheck/gui/projectfile.txt at master · danmar/cppcheck · GitHub



来源:https://stackoverflow.com/questions/22168480/make-cppcheck-skip-the-package-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!