【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()));
相关推荐
zh_xuan3 小时前
c++ 单例模式
开发语言·c++·单例模式
利刃大大5 小时前
【在线五子棋对战】二、websocket && 服务器搭建
服务器·c++·websocket·网络协议·项目
喜欢吃燃面6 小时前
C++刷题:日期模拟(1)
c++·学习·算法
SHERlocked936 小时前
CPP 从 0 到 1 完成一个支持 future/promise 的 Windows 异步串口通信库
c++·算法·promise
虚拟之7 小时前
36、stringstream
c++
我很好我还能学7 小时前
【面试篇 9】c++生成可执行文件的四个步骤、悬挂指针、define和const区别、c++定义和声明、将引用作为返回值的好处、类的四个缺省函数
开发语言·c++
南岩亦凛汀8 小时前
在Linux下使用wxWidgets进行跨平台GUI开发
c++·跨平台·gui·开源框架·工程实战教程
曦月逸霜8 小时前
第34次CCF-CSP认证真题解析(目标300分做法)
数据结构·c++·算法
galaxy_strive8 小时前
绘制饼图详细过程
开发语言·c++·qt
Unpredictable22210 小时前
【VINS-Mono算法深度解析:边缘化策略、初始化与关键技术】
c++·笔记·算法·ubuntu·计算机视觉