【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()));
相关推荐
可均可可11 分钟前
C++之OpenCV入门到提高004:Mat 对象的使用
c++·opencv·mat·imread·imwrite
白子寰33 分钟前
【C++打怪之路Lv14】- “多态“篇
开发语言·c++
小芒果_0138 分钟前
P11229 [CSP-J 2024] 小木棍
c++·算法·信息学奥赛
gkdpjj44 分钟前
C++优选算法十 哈希表
c++·算法·散列表
王俊山IT1 小时前
C++学习笔记----10、模块、头文件及各种主题(一)---- 模块(5)
开发语言·c++·笔记·学习
-Even-1 小时前
【第六章】分支语句和逻辑运算符
c++·c++ primer plus
我是谁??1 小时前
C/C++使用AddressSanitizer检测内存错误
c语言·c++
发霉的闲鱼2 小时前
MFC 重写了listControl类(类名为A),并把双击事件的处理函数定义在A中,主窗口如何接收表格是否被双击
c++·mfc
小c君tt2 小时前
MFC中Excel的导入以及使用步骤
c++·excel·mfc
xiaoxiao涛2 小时前
协程6 --- HOOK
c++·协程