C++ compile error when adding a newline in multicast delegate definition

I was attempting to improve readability of some of my multicast delegate definitions by spreading the definition over multiple lines. However, simply adding a newline causes a compile error.

This compiles:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSomeDelegateType, int32, ParamName);

This does not:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSomeDelegateType,
int32, ParamName);

The only difference between the two is I added a newline after the delegate name and before the parameter list. I get the following compile errors:

MyObject.h(13): error C2143: syntax error: missing ';' before '<class-head>'
MyObject.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
MyObject.h(13): error C3861: 'FSomeDelegateType_DelegateWrapper': identifier not found
MyObject.h(13): error C2143: syntax error: missing ';' before '<class-head>'
MyObject.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
MyObject.h(13): error C3861: 'FSomeDelegateType_DelegateWrapper': identifier not found

This is using the launcher version of UE 4.16.1 with a Visual Studio 2017 solution. Here’s a sample project with this issue: DelegateTest Project

Hi,

Those delegate declarations rely on a macro expansion which use the current line number (as defined by __LINE__ in C++) in their definition. As the value of __LINE__ is unspecified in multiline macro expansions, we cannot guarantee this will work in a portable way.

However, I’ve made a change to UnrealHeaderTool so that it always chooses the line with the closing bracket. This will at least work with Visual Studio. Unfortunately, it will not be available until the 4.18 release, so for now you should keep your delegate definitions to a single line.

Steve

I also received this error when I mistakenly tried to re-implement (duplicate) a same-named multicast delegate, so check your project and make sure the delegate has a unique name.