Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MSVC Code Analysis throwing warnings for Qt framework code
Forum Updated to NodeBB v4.3 + New Features

MSVC Code Analysis throwing warnings for Qt framework code

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 513 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taytoo
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • Christian EhrlicherC Christian Ehrlicher

      @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.

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #5

      @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.

      UPDATE: There have been improvements to this and now external code can be excluded also from code analysis. See this blog post for details: Customized Warning Levels and Code Analysis for External Headers

      1 Reply Last reply
      2
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #2

        there are warning level settings in vs studio. Certain type of warnings can be suppressed by selecting them.
        https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-160
        https://stackoverflow.com/questions/58900260/how-can-i-enable-compiler-warnings-in-visual-studio-2019

        T 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          there are warning level settings in vs studio. Certain type of warnings can be suppressed by selecting them.
          https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-160
          https://stackoverflow.com/questions/58900260/how-can-i-enable-compiler-warnings-in-visual-studio-2019

          T Offline
          T Offline
          Taytoo
          wrote on last edited by
          #3

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

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @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.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            Chris KawaC 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @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.

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #5

              @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.

              UPDATE: There have been improvements to this and now external code can be excluded also from code analysis. See this blog post for details: Customized Warning Levels and Code Analysis for External Headers

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved