Selectively disable C ++ Core Guidelines Checker for third-party libraries

I would like to try using the Key Pointer Checker in a C ++ 11/14 project under VS2015.

In my code I use a lot of libraries from Boost that cause a lot of warnings. These warnings do not bother me, because Boost does a lot of smart work, and the libraries were not written in order to comply with the Guides they basically betray.

But with such a stream of warnings, I cannot find out the real problems (at least according to the tool) in my code.

Is there a way to suppress all warnings for third-party code? Maybe there is some kind of attribute before and after #include boost headers?

I read this page from the Team Visual C ++ blog, but I could not find it.

+5
source share
2 answers

There is an undocumented environment variable, CAExcludePath, which filters warnings from files in this path. I usually run with% CAExcludePath% set to% Include%.

You can also use it from MSBuild, see an example here (with mixed success): Suppress warnings for external headers in VS2017 code analysis

MSVC is working on something similar to the headers of GCC systems, which should be a more comprehensive solution to this problem.

+1
source

Currently, in VS, the warning suppression function from third-party libraries is still experimental, but certainly suitable.

Version VS 2017 15.6. In preview mode 1, there is a function to suppress warnings from third-party libraries. In the next article, they use "external headers" as a term to refer to the headers of third-party libraries.

https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/

The above article basically says that

  • specify external headers
  • specify warning level for external headers

to suppress warnings from them. For example, if we have external headers in the some_lib_dir directory and we want to compile our code in my_prog.cpp , which depends on the external headers, the following command should complete the task.

cl.exe /experimental:external /external:I some_lib_dir /external:W0 /W4 my_prog.cpp

Note that /experimental:external is required because it is still an experimental function, and the details of this function may change in the future.

In any case, we need to wait for the future version of Visual Studio.

+1
source

Source: https://habr.com/ru/post/1271037/


All Articles