[Bug] UHT Pointer Const Error

Hi!

When compiling this type: UMyType* const MyVar, the UHT generates incorrect function signatures, of the form: const UMyType* MyVar. This causes a compile bug.

Example:

UFUNCTION( Category = "KeshIRC|Controller|Command Response Scanner", BlueprintNativeEvent )
void HandleCommand( UKIRCUser* const Source, const FString& Command, const TArray<FString>& Params, const FString& Message );

generates

void UKIRCCommandResponseScanner::HandleCommand(const UKIRCUser* Source, const FString& Command, const TArray<FString>& Params, const FString& Message)

Removing the const in the original function signature fixes the error. I’d still like my pointer to be const, though.

Yes they are. i use them a lot. There are not enough down vote buttons for that reply.

Hey TTaM-

The problem is the use of BluerpintNativeEvent. According to the code posted, you have a non-const pointer to a const object which does not translate to blueprints. If you make the pointer itself constant (as the generated function attempts to do) or make the UFUNCTION BlueprintCallable rather than a BlueprintNativeEvent then you should be able to compile successfully.

Cheers

Yeah. I’m not sure how I came to that conclusion. I must have been drunk.

Thanks for the reply, , but you have that the wrong way around. My initial parameter, “UKIRCUser* const Source”, is a const pointer to a non-const object. This is changed by the UHT into a variable pointer to a const object, which you say doesn’t translate to blueprints. Hence the bug report.

Hi TTaM,

You should be able to make your pointer non-const in the declaration but const in the definition. This is legal C++ as value-level consts are ignored in function signatures:

// Header.h
UCLASS()
class UMyClass : public UObject
{
    UFUNCTION()
    void HandleCommand( UKIRCUser* Source );
};

// Source.cpp
void UMyClass::HandleCommand( UKIRCUser* const Source )
{
    // Source is const here
}

This will give you the semantics you want, while avoiding the UHT parsing error.

Steve

Ah ha. Useful info, thanks!