Skip to content

Cannot build with VS2022 for UE5.4, unreachable code build failure in MenuItem #138

@RkShaRkz

Description

@RkShaRkz

Long story short, the build fails with "unreachable code" in Source/USK/Widgets/MenuItem.cpp, here on line 402:

/**
 * @brief Called when trying to go back in the menu
 * @return A boolean value indicating if the back event was handled
 */
bool UMenuItem::OnMenuBack()
{
#if ENGINE_MAJOR_VERSION >= 5
	if (!WaitingForKeyPress)
	{
		return false;		
	}

	WaitingForKeyPress = false;
	SetText(FText::GetEmpty());
	UpdateInputIndicator();
	return true;
#endif

	return false; //<-- unreachable code, when the preprocessor glues in the block behind the #if/#endif, it becomes a return true; followed by a return false; 
}

The fix for this is rather simple, instead of just using the #if/#endif, use the whole #if/#else/#endif construct.

/**
 * @brief Called when trying to go back in the menu
 * @return A boolean value indicating if the back event was handled
 */
bool UMenuItem::OnMenuBack()
{
#if ENGINE_MAJOR_VERSION >= 5
	if (!WaitingForKeyPress)
	{
		return false;		
	}

	WaitingForKeyPress = false;
	SetText(FText::GetEmpty());
	UpdateInputIndicator();
	return true;
#else
	/**
	* Shark changed this, put the #else part in, and moved the "return false;" between the #else and #endif to avoid the following build error
    * U:\Unreal Projects\5.4.4\BlankCppProject\Plugins\UltimateStarterKit-UE5.3-shark\Source\USK\Widgets\MenuItem.cpp(402): error C4702: unreachable code
	*/
	return false;
#endif
}

I'm too lazy to fork and push out a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions