#pragma region directive not working in USTRUCT

Hello,

I usually use #pragma region and #pragma endregion directives to specify regions in my code to collect methods, class members which belong to a specific category. This makes my huge header and cpp files easier to read.

Today I’ve just noticed a very peculiar thing.

For the first time I put a #pragma region definition inside a struct (defined with USTRUCT). And then I got the following

“Unexpected ‘}’. Did you miss a semi-colon?”

regions inside Classes on the other hand work fine.

When I remove these #pragma directives the code compiles just fine.

It appears that this issue occurs if I have not one but multiple regions inside the struct.

This appears to be a problem with the unreal’s pre build step in which the “*.generated.h” are created.

Seems like the code which reads the USTRUCTS does something strange on #pragma directives and forgets to put a semi-colon in the generated header file somewhere… I am not sure though.

This took like 2-3 hours for me to figure out that this issue occurs because of the #pragma directives.

Can anyone else confirm this?

Hi,

Can you post a small example of failing code, please? UnrealHeaderTool already skips unrecognised #pragmas, so there should be no effect.

Steve

Here is an example:

USTRUCT(Blueprintable, Category = "FOO")
struct TWVR_API FFooStruct
{
	GENERATED_BODY()

	
	UPROPERTY(BlueprintReadonly, VisibleAnywhere)
	float fooMember;
	
	#pragma region METHODS
	public:
	FFooStruct();

	void DoFoo();
	#pragma endregion METHODS
	
};

If I comment out the #pragma directives this struct compiles just fine. With them I get the following error:

“FooStruct.h(26): error : Unexpected ‘}’. Did you miss a semi-colon?”

It appears that having multiple pragma directives is not important. Seems like this occurs when you put a pragma directive around a method. If you cut-paste the same pragma directives above so that they cover only the fooMember then it again compiles just fine.

I can confirm that this isn’t being handled by the UnrealHeaderTool and have made a PR #3287 with a potential solution (yet to be evaluated by Epic).

Cheers,

Hi,

I’ve integrated project.gheist’s PR #3287. It should be available in 4.16.

Thanks for the bug report!

Steve