【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

原因

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()));
相关推荐
Mr YiRan8 分钟前
JNI技术之手写JNIEnv与静态缓存与native异常
java·c++
飞翔的SA14 分钟前
全程 Python:无需离开 Python 即可实现光速级 CUDA 加速,无需c++支持
开发语言·c++·python·nvidia·cuda
SccTsAxR19 分钟前
算法进阶:贪心策略证明全攻略与二进制倍增思想深度解析
c++·经验分享·笔记·算法
CoderMeijun27 分钟前
CMake 入门笔记
c++·笔记·编译·cmake·构建工具
楼田莉子28 分钟前
设计模式:创建型设计模式简介
服务器·开发语言·c++·设计模式
啦啦啦!37 分钟前
c++AI大模型接入SDK项目
开发语言·数据结构·c++·人工智能·算法
cmpxr_1 小时前
【C】隐式类型转换
c语言·c++·算法
大江东去浪淘尽千古风流人物1 小时前
【Basalt】nfr_mapper 中的“小 SfM/BA 后端”
c++·人工智能·计算机视觉·oracle·augmented reality
Magic--1 小时前
C++ STL中vector与list的核心区别
c++·windows·list
初願致夕霞1 小时前
Linux_线程
linux·运维·服务器·c++