欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > 【VS2022 编译UE5.1 错误 C4834 】

【VS2022 编译UE5.1 错误 C4834 】

2024/10/24 21:33:06 来源:https://blog.csdn.net/yaoyutian/article/details/139631015  浏览:    关键词:【VS2022 编译UE5.1 错误 C4834 】

这里写自定义目录标题

  • 错误

错误

使用VS2022编译UE5.1源码,错误 C4834 放弃具有 [[nodiscard]] 属性的函数的返回值

F:\UE\Engine\Plugins\Runtime\Steam\SteamVR\Source\SteamVRInputDevice\Private\SteamVRInputDeviceFunctionLibrary.cpp(513): error C4834: discarding return value of function with 'nodiscard' attribute

原因

  • 编译器警告(等级 1)C4834
  • 详细解释

This is a bug in the UE code on line 513.
It should probably be:

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Unable to find Action [%s] for Action Set [%s]"), *ActionName.ToString(), *ActionSet.ToString()));

instead of:

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, (TEXT("Unable to find Action [%s] for Action Set [%s]"), *ActionName.ToString(), *ActionSet.ToString()));

Actually the problem is in the substring:

(TEXT("Unable to find Action [%s] for Action Set [%s]"), *ActionName.ToString(), *ActionSet.ToString())

This line is like:

const TCHAR *value = (TEXT("some value"), name1.CalculateString(), name2.CalculateString());

or

auto a = (op1(), op2(), op3());

the results of calling op1 and op2 will be ignored, but only op3() will be assigned to a.
So, if op1 or op2 has a “nodiscard” attribute, Visual Studio will generate an error/warning.
The previous version of Visual Studio did not have this behavior. New Visual Studio update - has.

The actual nodiscard attribute that can cause this error in this situation is UnrealString.h, line 324:

/*** Get pointer to the string** @Return Pointer to Array of TCHAR if Num, otherwise the empty string*/
UE_NODISCARD FORCEINLINE const TCHAR* operator*() const UE_LIFETIMEBOUND
{return Data.Num() ? Data.GetData() : TEXT("");
}

To sum up, the solution would be to use this line instead of line 513:

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Unable to find Action [%s] for Action Set [%s]"), *ActionName.ToString(), *ActionSet.ToString()));

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com