cxx icon indicating copy to clipboard operation
cxx copied to clipboard

C++ MaybeUninit triggers MSVC warning C4582

Open CAD97 opened this issue 4 years ago • 1 comments

Specifically,

warning C4582: 'rust::cxxbridge1::MaybeUninit<FVector2D>::value': constructor is not implicitly called

This is a Level 4 warning (/Wall), which is rarely enabled in MSVC projects due to a similar rate of false positive annoyance and questionable advice as clippy::pedantic. Unfortunately, it's enabled as an error in at least one major project (cough Unreal Engine cough) so it's worth avoiding raising this warning.

Given we don't expect the generated code to compile cleanly at level 4, the correct thing to do would be to push the warning state to level 3 and restore the level state afterwards, as described in the MS docs.

#pragma warning( push, 3 )
// Declarations/definitions
#pragma warning( pop )

Some context:

  • https://github.com/akrzemi1/Optional/issues/57
  • https://answers.unrealengine.com/questions/607946/anonymous-union-with-none-trivial-type.html

CAD97 avatar Aug 14 '21 02:08 CAD97

The warning is actually emitted from the .cxx file, so it might be prudent to #pragma warning( default ) in the generated code for compilation as well.

CAD97 avatar Aug 14 '21 02:08 CAD97