【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()));

相关推荐

  1. VS2022 编译UE5.1 错误 C4834

    2024-06-13 16:40:04       35 阅读
  2. Windows下 VS2022 编译OpenSSL 库

    2024-06-13 16:40:04       48 阅读
  3. ffmpeg 7.0 + vs2022 +windows编译

    2024-06-13 16:40:04       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-13 16:40:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-13 16:40:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-13 16:40:04       87 阅读
  4. Python语言-面向对象

    2024-06-13 16:40:04       96 阅读

热门阅读

  1. 算法训练营day58

    2024-06-13 16:40:04       35 阅读
  2. 绝对人机交互和相对人机交互

    2024-06-13 16:40:04       33 阅读
  3. 狭义人机交互与广义人机交互

    2024-06-13 16:40:04       29 阅读
  4. Oracle数据库面试题-12

    2024-06-13 16:40:04       20 阅读
  5. 算法第9章 图算法设计

    2024-06-13 16:40:04       21 阅读
  6. define与typedef的区别和使用

    2024-06-13 16:40:04       31 阅读
  7. 图片角度调整 适配缩放 transform scale rotate

    2024-06-13 16:40:04       30 阅读
  8. 微服务——参数校验

    2024-06-13 16:40:04       25 阅读
  9. linux 环境下动态链接库试验

    2024-06-13 16:40:04       29 阅读