MSVC Code Analysis throwing warnings for Qt framework code
-
@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.
@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, sayC:\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
-
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 -
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 -
@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.
-
@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.
@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, sayC:\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