Can't compile after upgrading to 4.17, syntax error in gen.cpp

I’m attempting to upgrade my project from a custom 4.16.3 build to 4.17. I’ve managed to jump through the most obvious hoops but I’m now getting errors inside the gen.cpp files for every class that contains an AddDynamic binding.

C:\Users\quinc\Documents\Unreal Projects\ProxyWarVR 4.15\Intermediate\Build\Win64\UE4Editor\Inc\ProxyWarVR\FlyDudesBotSpawnTriggerBox.gen.cpp(33): error C2059: syntax error: ')'
C:\Users\quinc\Documents\Unreal Projects\ProxyWarVR 4.15\Intermediate\Build\Win64\UE4Editor

Looking at the code, this appears to always happen in the same place:

	void AProxyWarVRPluginCharacter::StaticRegisterNativesAProxyWarVRPluginCharacter()
	{
		UClass* Class = AProxyWarVRPluginCharacter::StaticClass();
		static const TNameNativePtrPair<ANSICHAR> AnsiFuncs[] = {
			{ "ExtendedSimpleMoveToLocation", (Native)&AProxyWarVRPluginCharacter::execExtendedSimpleMoveToLocation },
			{ "GetTeleportLocation", (Native)&AProxyWarVRPluginCharacter::execGetTeleportLocation },
			{ "NotifyOfTeleport", (Native)&AProxyWarVRPluginCharacter::execNotifyOfTeleport },
		};
		FNativeFunctionRegistrar::RegisterFunctions(Class, AnsiFuncs, ARRAY_COUNT(AnsiFuncs));
	}

On the RegisterFunctions call. I’m getting a few suspicious warnings from the steamworks api as well:

c:\program files\epic games\ue_4.17\engine\source\thirdparty\steamworks\steamv139\sdk\public\steam\steamtypes.h(99): warning C4005: 'ARRAY_COUNT': macro redefinition
c:\program files\epic games\ue_4.17\engine\source\runtime\core\public\Templates/UnrealTemplate.h(135): note: see previous definition of 'ARRAY_COUNT'
c:\program files\epic games\ue_4.17\engine\source\thirdparty\steamworks\steamv139\sdk\public\steam\matchmakingtypes.h(45): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(346): note: see declaration of 'strncpy'
c:\program files\epic games\ue_4.17\engine\source\thirdparty\steamworks\steamv139\sdk\public\steam\matchmakingtypes.h(47): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(346): note: see declaration of 'strncpy'
c:\program files\epic games\ue_4.17\engine\source\thirdparty\steamworks\steamv139\sdk\public\steam\matchmakingtypes.h(161): warning C4996: '_snprintf': This function or variable may be unsafe. Consider using _snprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\stdio.h(1952): note: see declaration of '_snprintf'
c:\program files\epic games\ue_4.17\engine\source\thirdparty\steamworks\steamv139\sdk\public\steam\matchmakingtypes.h(246): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\string.h(346): note: see declaration of 'strncpy'
C:\Program Files\Epic Games\UE_4.17\Engine\Source\ThirdParty\Steamworks\Steamv139\sdk\public\steam/steam_api.h(273): warning C4265: 'CCallbackImpl<24>': class has virtual functions, but destructor is not virtual
         instances of this class may not be destructed correctly

I suspect the ARRAY_COUNT macro redefinition is the culprit here, somehow. That warning was popping up in 4.16 too, as well as the strncpy warning, but something has clearly changed because the CCallbackImpl warning is new.

Hey SlimeQ-

When you say “from a custom 4.16.3 build to 4.17” is the 4.17 engine custom from source as well? I tried adding a component and creating an OnComponentBeginOverlap.AddDynamic(); call in the constructor but was still able to compile without issue. Do you get the same error in a new project if you add the AddDynamic call?

4.17 is a binary build. I was able to fix this, it definitely has to do with the ARRAY_COUNT macro redefinition in the steamworks api

I was able to fix this by going into the steamworks api (C:\Program Files\Epic Games\UE_4.17\Engine\Source\ThirdParty\Steamworks\Steamv139\sdk\public\steam) and replacing all instances of ARRAY_COUNT to STEAM_ARRAY_COUNT. I was getting a macro redefinition warning in 4.16 also but apparently something about the way 4.17 generates code made this cause a syntax error on AddDynamic.

Thank you, finally I can compile my 4.17 project

Same issue, fixed with this.

Had a similar problem. Fixed it by defining the ARRAY_COUNT back to what it was after the steam api include. Like this in my header file…

#pragma once

#include "Engine/GameInstance.h"
#include "OnlineSessionInterface.h"

#include "steam/steam_api.h"
#define ARRAY_COUNT( array ) (sizeof(ArrayCountHelper(array)) - 1)

#include "DSSGameInstanceBase.generated.h"

This seems like a much less obnoxious solution than mine, thanks for the tip

Just found this little bit in the AdvancedSteamSessions plugin:

#pragma push_macro("ARRAY_COUNT")
#undef ARRAY_COUNT

#if USING_CODE_ANALYSIS
MSVC_PRAGMA(warning(push))
MSVC_PRAGMA(warning(disable : ALL_CODE_ANALYSIS_WARNINGS))
#endif	// USING_CODE_ANALYSIS

#include <steam/steam_api.h>

#if USING_CODE_ANALYSIS
MSVC_PRAGMA(warning(pop))
#endif	// USING_CODE_ANALYSIS


#pragma pop_macro("ARRAY_COUNT")

While a little lengthy, I think this is probably technically better than SND R Keene’s answer since it won’t be affected if ARRAY_COUNT ever changes for some reason.

Your solution fixed it for me! I couldnt compile when I was include Steam_Api.h

Thanks so much!

Thanks for this! It’s unfortunate that we have to deal with this.