My code will not compile

Registered process C:\Program Files\Epic Games\UE_5.0\Engine\Binaries\Win64\UnrealEditor.exe (PID: 9000)
Loading module D:\Unreal Projects\BullGame\BullCowGame-starter-kit\Binaries\Win64\UnrealEditor-BullCowGame.dll (0.135 MB)
No PDB file found for module UnrealEditor-LiveCoding.dll. If this is a packaged build, make sure that debug files are being staged. Live coding will be disabled for this module.
Loaded 1 module(s) (0.000s, 11 translation units)
Live coding ready - Save changes and press CTRL+ALT+F11 to re-compile code
Manual recompile triggered
---------- Creating patch ----------
Running C:\Program Files\Epic Games\UE_5.0\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe -Target="BullCowGameEditor Win64 Development -Project=""D:/Unreal Projects/BullGame/BullCowGame-starter-kit/BullCowGame.uproject""" -LiveCoding -LiveCodingModules="C:/Program Files/Epic Games/UE_5.0/Engine/Intermediate/LiveCodingModules.txt" -LiveCodingManifest="C:/Program Files/Epic Games/UE_5.0/Engine/Intermediate/LiveCoding.json" -WaitMutex -LiveCodingLimit=100
Quick restart disabled when re-instancing is enabled.
  Log file: C:\Users\cooke\AppData\Local\UnrealBuildTool\Log.txt
  Building BullCowGameEditor...
  Using Visual Studio 2022 14.30.30709 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
  [Upgrade]
  [Upgrade] Using backward-compatible build settings. The latest version of UE sets the following values by default, which may require code changes:
  [Upgrade]     bLegacyPublicIncludePaths = false                 => Omits subfolders from public include paths to reduce compiler command line length. (Previously: true).
  [Upgrade]     ShadowVariableWarningLevel = WarningLevel.Error   => Treats shadowed variable warnings as errors. (Previously: WarningLevel.Warning).
  [Upgrade]     PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs   => Set in build.cs files to enables IWYU-style PCH model. See https://docs.unrealengine.com/en-US/Programming/BuildTools/UnrealBuildTool/IWYU/index.html. (Previously: PCHUsageMode.UseSharedPCHs).
  [Upgrade] Suppress this message by setting 'DefaultBuildSettings = BuildSettingsVersion.V2;' in BullCowGameEditor.Target.cs, and explicitly overriding settings that differ from the new defaults.
  [Upgrade]
  [Adaptive Build] Excluded from BullCowGame unity file: Cartridge.cpp, Terminal.cpp, BullCowCartridge.cpp, BullCowGame.cpp, BullCowGameGameModeBase.cpp
  Determining max actions to execute in parallel (6 physical cores, 6 logical cores)
    Executing up to 6 processes, one per physical core
    Requested 1.5 GB free memory per action, 8.77 GB available: limiting max parallel actions to 5
  Building 1 action with 1 process...
  [1/1] Compile BullCowCartridge.cpp
  D:\Unreal Projects\BullGame\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(21): error C4834: discarding return value of function with 'nodiscard' attribute
Build failed.

Does anyone know why that won’t compile. I have tried restarting the editor and tried building directly from Visual Studio.

You have a compilation error.

Unreal has marked several functions as “nodiscard” which tells the compiler to issue a warning if the return value of calling a function is discarded, Unreal also has that warning treated as an error.

So what does discarding the return value mean?

[[nodiscard]] int square(int n)
{
    return n * n;
}

int main()
{
    square(3); // warning return value discarded.
}

Here square is called and a value is then returned but discarded, it’s never used. The function gets called and the result is basically just thrown away. However square has no side effects, the only reason to ever call that function is get the value returned from it, it doesn’t do anything else. So discarding it very likely to be a bug.

This is why Unreal has marked these functions as nodiscard, to help catch bugs.

You’re probably on the lecture going over syntax of pointers where Mike calls Len(); but like square above, the only reason to call that function is to get the result of it. It doesn’t do anything else.

However Mike is just demonstrating the syntax and ends up deleting the code. Either save the result or just make sure you understand the syntax and what’s happening but don’t compile.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms