Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MSVC Code Analysis throwing warnings for Qt framework code



  • Ran MSVC17 code Analysis on my project and its throwing hundreds of warning in Qt header files. See screenshot below. Is there a way to stop msvc from analyzing Qt header files?

    0ae41d56-249c-4576-8bfe-8851f58a7029-image.png


  • Moderators

    @Christian-Ehrlicher said:

    msvc doesn't know the concept of 'system headers'.

    It does. It just calls them "external headers", which is IMO a better name for it, as there is nothing system about Qt on Windows for example.

    @Taytoo
    If you want to skip all compilation warnings from, say C:\Qt\Qt5.12.2, you can do it like this:
    /experimental:external /external:W0 /external:I C:\Qt\Qt5.12.2
    The first switch enables this feature (it's experimental). The second one sets the warning level for external headers (W0 disables them entirely) and the third one sets a path to treat as external.

    But that's really not the problem. The question was about the static code analysis tool and those switches unfortunately won't work with that. VS static analysis tool does not have warning levels so there's no switches to configure it.

    The current solution MS suggest for that is something like this:

    #include <codeanalysis\warnings.h>
    #pragma warning( push )
    #pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
    #include <Qt includes you use>
    #pragma warning( pop )
    

    which, admittedly, is quite ugly and invasive. It also has a nasty side effect of silencing everything that gets included transitively from Qt, so make sure Qt headers are last on your include list.





  • @JoeCFD Was hoping to suppress them for Qt header files only. Is that possible?


  • Lifetime Qt Champion

    @Taytoo said in MSVC Code Analysis throwing warnings for Qt framework code:

    Is that possible?

    With any other compiler yes, but msvc doesn't know the concept of 'system headers'. There were some efforts to add a similar stuff (but as always much more complicated than it's for gcc/clang) but don't know the current state ofit.


  • Moderators

    @Christian-Ehrlicher said:

    msvc doesn't know the concept of 'system headers'.

    It does. It just calls them "external headers", which is IMO a better name for it, as there is nothing system about Qt on Windows for example.

    @Taytoo
    If you want to skip all compilation warnings from, say C:\Qt\Qt5.12.2, you can do it like this:
    /experimental:external /external:W0 /external:I C:\Qt\Qt5.12.2
    The first switch enables this feature (it's experimental). The second one sets the warning level for external headers (W0 disables them entirely) and the third one sets a path to treat as external.

    But that's really not the problem. The question was about the static code analysis tool and those switches unfortunately won't work with that. VS static analysis tool does not have warning levels so there's no switches to configure it.

    The current solution MS suggest for that is something like this:

    #include <codeanalysis\warnings.h>
    #pragma warning( push )
    #pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
    #include <Qt includes you use>
    #pragma warning( pop )
    

    which, admittedly, is quite ugly and invasive. It also has a nasty side effect of silencing everything that gets included transitively from Qt, so make sure Qt headers are last on your include list.


Log in to reply