Version
3.0.260520.1
Summary
I switch yesterday my open source project from using my own C++ module wrapper of winrt to the v3 implementation. In my release build configuration I have Microsoft Code Analysis enabled with a custom ruleset.
To be able to use v3 I had to disable a couple of analysis rules to prevent warnings reported on base.h as my project uses the option warnings are errors.
It is not 100% clear to me why MSVC reports these warnings from base.h in my consuming project as for my project base.h is external code. I tried several ways to silence these warnings but at the end was forced to disable these warnings in my custom ruleset file.
I used to create a module from winRT v2 using my own winrt.ixx file:
module;
#include <Unknwn.h> // Required to enable classic COM support in WinRT.
#pragma warning(push)
#pragma warning(disable : 4265) // : '' : class has virtual functions, but its non-trivial destructor is not virtual
#pragma warning(disable : 4946) // reinterpret_cast used between related classes
#pragma warning(disable : 5204) // class has virtual functions, but its trivial destructor is not virtual
#pragma warning(disable : 5260) // the constant variable has external\internal linkage
#pragma warning(disable : 26432) // If you define or delete any default operation in the type define or delete them.
#include <winrt/base.h>
#pragma warning(pop)
export module winrt;
export namespace winrt {
using winrt::check_hresult;
using winrt::check_win32;
// ... etc.
}
The CA warnings that I needed to disable were:
- C26436: The type X with a virtual function needs either public virtual or protected non-virtual destructor (c.35).
- C26432: f you define or delete any default operation in the type define or delete them all (c.21).
- C26466: Don't use static_cast downcasts. A cast from a polymorphic type should use dynamic_cast (type.2).
- C26493: Don't use C-style casts (type.4).
- C26473: Don't cast between pointer types where the source type and the target type are the same (type.1).
- C26496: The variable 'hr' does not change after construction, mark it as const (con.4).
- C26497: You can attempt to make '' constexpr
- C26409: Avoid calling new and delete explicitly, use std::make_unique<T> instead (r.11).
- C26447: The function is declared 'noexcept' but calls function 'AddRef()' which may throw exceptions (f.6).
- C26465: Don't use const_cast to cast away const or volatile. const_cast is not required; constness or volatility is not being
Reproducible example
1) git clone --recurse-submodules https://github.com/team-charls/jpegls-wic-codec
2) Remove some of the last 5 rule suppressions from default.ruleset (for example C26465)
3) Build the release configuration -> Code Analysis warnings are reported coming from base.h
Note: I can create a smaller example that demonstrates the problem if that makes reproducing easier.
Expected behavior
No C2xxxx warnings are reported when building the consuming project.
Actual behavior
Warnings were reported, requiring to disable these rules globally.
Additional comments
-
MSVC has an option to suppress warnings coming from external include headers. As the winrt_base.ixx includes base.h with "" instead of <> I was not able to suppress the warnings in this way.
-
There are also some other ways to suppress CA warnings, but I was not able to find a setting that worked, but there may still be a method I missed.
-
This issue report is not about if the code in base.h should not generate these kinds of warnings: that would another discussion. This report is a request for a method to keep the rules enabled globally for my own code and a way to suppress them when coming from base.h.
Version
3.0.260520.1
Summary
I switch yesterday my open source project from using my own C++ module wrapper of winrt to the v3 implementation. In my release build configuration I have Microsoft Code Analysis enabled with a custom ruleset.
To be able to use v3 I had to disable a couple of analysis rules to prevent warnings reported on base.h as my project uses the option warnings are errors.
It is not 100% clear to me why MSVC reports these warnings from base.h in my consuming project as for my project base.h is external code. I tried several ways to silence these warnings but at the end was forced to disable these warnings in my custom ruleset file.
I used to create a module from winRT v2 using my own winrt.ixx file:
The CA warnings that I needed to disable were:
Reproducible example
Expected behavior
No C2xxxx warnings are reported when building the consuming project.
Actual behavior
Warnings were reported, requiring to disable these rules globally.
Additional comments
MSVC has an option to suppress warnings coming from external include headers. As the winrt_base.ixx includes base.h with "" instead of <> I was not able to suppress the warnings in this way.
There are also some other ways to suppress CA warnings, but I was not able to find a setting that worked, but there may still be a method I missed.
This issue report is not about if the code in base.h should not generate these kinds of warnings: that would another discussion. This report is a request for a method to keep the rules enabled globally for my own code and a way to suppress them when coming from base.h.