These come with even better usability and maintainability as they are all available through the VS IDE. With these options, code analysis of external headers can be turned off, or use a separate ruleset from the rest of the codebase. While we decided to leave “CAExcludePath” option as is, we strongly recommend to switch to the /external:* and /analyze:external* options. We now have a better solution to control code analysis behavior for external files. To support one of the most common requirements of suppressing code analysis warnings for defects in library headers over which developers have no control, we created a temporary solution to use a special environment variable (“CAExcludePath”), that can be used to specify directories for which code analysis will not report any warnings. Migration from undocumented CAExcludePath to /external:* and /analyze:external* options The examples below show some of the ways you can leverage this new feature to get the most out of Code Analysis. You can customize the way external headers are treated in the project properties “C/C++ > External Includes” tab.Ĭustomizing Code Analysis Settings for External Headersīeing able to mark certain headers as external to the project will make Code Analysis much easier to use. Customizing Warning Levels External Headers In Visual Studio 2019, we will continue to also include the toolset and Windows SDK headers in the existing “Include Directories” property for backwards compatibility, but in the next major release of Visual Studio this will be removed. If you want to ensure that the project builds properly with earlier versions, you will need to make sure that any “External Include Directories” are also listed in the “Include Directories” property or they will not be found by the compiler. Keep in mind that this new property will be ignored by earlier versions of the toolset. However, you can add any other include directories (such as 3 rd party libraries) to this new property, separated by a semicolon as well. From a compilation standpoint, you won’t notice any differences, but you can choose a different set of warning levels and other analysis settings for headers in these directories.īy default, all headers from the toolset and the Windows SDK are included as external headers. This external include directory will be added to the include search path as normal, but every header that in that directory or a subdirectory of it will be treated as external. You can find a new “External Include Directories” property for your projects under “VC++ Directories” which can be used to designate any include directory as containing external headers. This leaves you free to choose stricter settings for your project’s code to enforce code quality without getting bogged down with warnings from headers that are beyond your control. These external headers can have their own compiler warning level, code analysis, and template diagnostics settings. I’m happy to announce that, thanks to this feedback, external headers are now officially supported by the compiler, code analysis, and integrated into the IDE. Some of you may remember our previous post, Broken Warnings Theory, when we added experimental external header support to the Microsoft C++ Compiler. This is something we have been working on for a while with help and feedback from the community. To alleviate this, we’ve made it easy to mark headers as external to your project in the latest preview Visual Studio 2019. If you have tried to keep your code clean by selecting strict compiler warning levels or code analysis rulesets, you likely know how frustrating it can be to see these warnings for headers that are not part of your project.
0 Comments
Leave a Reply. |