8

I want to use the Code Analysis in Visual Studio 2017 but I'm using Qt and it gives me a lot of warnings from the headers. I've tried turning off warnings:

#pragma warning(push, 0)
#include <QtGlobal>
#pragma warning(pop)

but it doesn't help. I also tried using this:

#include <codeanalysis\warnings.h>
#pragma warning(push, 0)
#pragma warning(disable : ALL_CODE_ANALYSIS_WARNINGS)
#include <QtGlobal>
#pragma warning(pop)

but no help. How can I disable the Code Analysis for the Qt external headers?

Community
  • 1
  • 1
parsley72
  • 8,449
  • 8
  • 65
  • 98
  • 1
    But that will disable the warnings on the entire codebase. I just want it to ignore external headers. – parsley72 May 03 '17 at 10:31

1 Answers1

9

If you open your .vcxproj file, down the bottom you should see:

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>

below this you can add:

  <PropertyGroup Condition="'$(Language)'=='C++'">
    <IncludePath>$(QTDIR)\include;.\GeneratedFiles;$(IncludePath)</IncludePath>
    <CAExcludePath>$(QTDIR)\include;.\GeneratedFiles;$(CAExcludePath)</CAExcludePath>
  </PropertyGroup>

Microsoft say there's a bug where CAExcludePath is overwritten by IncludePath but this is fixed in Visual Studio 2017 V15.3 and you'll only need to set CAExcludePath - I haven't verified this (I'll update this once I do).

This answer came from How can I suppress warnings for external headers in VS2017 Code Analysis?

parsley72
  • 8,449
  • 8
  • 65
  • 98
  • 2
    Tried this solution, but this is not working for me. I see that CAExcludePath is set correctly, but I still get warnings from compilation of 3rd party headers. I'm using version 15.2 (26430.6) Release. Also tried to set CAExcludePath in Microsoft.CodeAnalysis.Targets, no success. – Quarra Jul 17 '17 at 09:54
  • 1
    Also, you can drop this into a property sheet as a "user macro". I found that I needed to check the box that says "Set this macro as an environment variable in the build environment". – Tim Finer Jan 30 '18 at 00:09
  • 1
    You don't need as far as I can tell. I've just disabled warnings for boost this way in VS 15.7. – Alexander Revo Jul 17 '18 at 23:24