How can I resolve an unmatched #endif Issue?

My typical coding style uses the following

#ifndef EXAMPLE_H
#define EXAMPLE_H

// Insert Code here

#endif

As opposed to:

#pragma once

However, I’m making a plugin and one of it’s elements is a subclass for UActorComponent and if I use #ifndef preprocessors in the class header file I get the error:

.../Classes/MyCustomComponent.h: error : In MyCustomComponent: Unmatched '#endif' in class or global scope

Commenting out the preprocessor header guards resolves this yet looking at the #include hierarchy I cannot see why this issue is present to begin with. Sample code which produces this issue is as follows:

MyCustomComponent.h (Version produces unmatched #endif error)

#ifndef PLUGIN_MyCustomComponent_h
#define PLUGIN_MyCustomComponent_h

#include "MyCustomComponent.generated.h"

UCLASS(HeaderGroup=Component, DependsOn = (UScene, UEngineTypes), BlueprintType, meta=(BlueprintSpawnableComponent))
class UMyCustomComponent: public UActorComponent
{
	GENERATED_UCLASS_BODY()

	private:

		virtual void InitializeComponent(void) OVERRIDE;
};

#endif

MyCustomComponent.h (Version resolves error but is undesirable coding style)

#pragma once

#include "MyCustomComponent.generated.h"

UCLASS(HeaderGroup=Component, DependsOn = (UScene, UEngineTypes), BlueprintType, meta=(BlueprintSpawnableComponent))
class UMyCustomComponent: public UActorComponent
{
	GENERATED_UCLASS_BODY()

	private:

		virtual void InitializeComponent(void) OVERRIDE;
};

This includes the generated file, which I’ll share below in case that helps too. As well as ObjectBase.h. Looking at both of these files I cannot see where this issue would be generated from so I’m unsure if there is some nmake compiler logic here that I’m unaware of or is this a bug?

MyCustomComponent.generated.h

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
/*===========================================================================
	C++ class header boilerplate exported from UnrealHeaderTool.
	This is automatically generated by the tools.
	DO NOT modify this manually! Edit the corresponding .h files instead!
===========================================================================*/

#include "ObjectBase.h"

#ifdef MYPLUGIN_MyCustomComponent_generated_h
#error "MyCustomComponent.generated.h already included, missing '#pragma once' in MyCustomComponent.h"
#endif
#define MYPLUGIN_MyCustomComponent_generated_h

#define UMyCustomComponent_EVENTPARMS
#define UMyCustomComponent_RPC_WRAPPERS
#define UMyCustomComponent_CALLBACK_WRAPPERS
#define UMyCustomComponent_INCLASS \
	private: \
	static void StaticRegisterNativesUMyCustomComponent(); \
	friend MYPLUGIN_API class UClass* Z_Construct_UClass_UMyCustomComponent(); \
	public: \
	DECLARE_CLASS(UMyCustomComponent, UActorComponent, COMPILED_IN_FLAGS(0), 0, MyPlugin, NO_API) \
	/** Standard constructor, called after all reflected properties have been initialized */    NO_API UMyCustomComponent(const class FPostConstructInitializeProperties& PCIP); \
	DECLARE_SERIALIZER(UMyCustomComponent) \
	/** Indicates whether the class is compiled into the engine */    enum {IsIntrinsic=COMPILED_IN_INTRINSIC};


#undef UCLASS_CURRENT_FILE_NAME
#define UCLASS_CURRENT_FILE_NAME UMyCustomComponent


#undef UCLASS
#undef UINTERFACE
#define UCLASS(...) \
UMyCustomComponent_EVENTPARMS


#undef GENERATED_UCLASS_BODY
#undef GENERATED_IINTERFACE_BODY
#define GENERATED_UCLASS_BODY() \
public: \
	UMyCustomComponent_RPC_WRAPPERS \
	UMyCustomComponent_CALLBACK_WRAPPERS \
	UMyCustomComponent_INCLASS \
public:

Hello, Arthain-Baka. Take a look at the answer to this question and see if it helps with the issue you have been having. If it does, please reply and let us know.

Have a great day.

I want to add that #pragma once is fine. It works on all platforms that we support, and we are gradually removing all our #ifdef/#endif header guards in the Engine.

Yeah, that work around also works. Mainly I just wanted to know why it was being produced because I was fairly certain there wasn’t anything on my side causing the error.
It’s more of a case of having a different coding style with certain files that bothered me about it.