Getting "error C4756: overflow in constant arithmetic" while building Unreal 5.4.2 from source code

To resume, options:

  1. Patching Unreal code as in @MeloinUnreal post. This is quite invasive fix though, but the right way to go. Should be accepted as a PR.

  2. Modify your C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_math.h

    #define INFINITY ((const float)“\x00\x00\x80\x7F”)

    This affects all your C++ projects though the change is benign. You will have to keep patching upcoming Windows SDK to keep it working.

  3. Patch your UnrealBuildTool, at Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs inside CreateTargetRulesInstance look for Rules.GlobalDefinitions setup and, for example, after:

    if (Rules.bDisableUnverifiedCertificates)
    {
    Rules.GlobalDefinitions.Add(“DISABLE_UNVERIFIED_CERTIFICATE_LOADING=1”);
    }

    Add:
    // workaround for “overflow in constant arithmetic” error using INFINITY macro
    Rules.GlobalDefinitions.Add(“_UCRT_LEGACY_INFINITY=1”);