Suppress warnings for external headers in VS2017 Code Analysis

和自甴很熟 提交于 2019-12-18 13:39:53

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/43755499/suppress-warnings-for-external-headers-in-vs2017-code-analysis

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