From 897ee4f283cdad1075603013dafe84e759c75d51 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Tue, 26 Apr 2022 23:04:50 +0800 Subject: [PATCH] fix(miscellaneous): fix misbehavior of assertions under some build types --- .../Private/Testing/MiscellaneousTesting.cpp | 8 ++++---- .../Public/Miscellaneous/AssertionMacros.h | 7 ++++++- .../Source/Public/Templates/Atomic.h | 12 ++++++------ .../Source/Public/Templates/Variant.h | 16 ++++++++-------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp b/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp index 49a536f..4b9c303 100644 --- a/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp @@ -53,13 +53,13 @@ void TestAssertionMacros() { check(true); //check(false); - checkf(true, "True!"); - //checkf(false, "False!"); + checkf(true, TEXT("True!")); + //checkf(false, TEXT("False!")); always_check(true); //always_check(false); - always_checkf(true, "True!"); - //always_checkf(false, "False!"); + always_checkf(true, TEXT("True!")); + //always_checkf(false, TEXT("False!")); //TestNoEntry(); diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/AssertionMacros.h b/Redcraft.Utility/Source/Public/Miscellaneous/AssertionMacros.h index 07a054a..53c224c 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/AssertionMacros.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/AssertionMacros.h @@ -3,8 +3,13 @@ #include "CoreTypes.h" #include "Miscellaneous/PreprocessorHelpers.h" +#ifdef NDEBUG #undef NDEBUG #include +#define NDEBUG 1 +#else +#include +#endif NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) @@ -37,7 +42,7 @@ NAMESPACE_PRIVATE_END #define always_check_no_recursion() static uint8 PREPROCESSOR_JOIN(RecursionCounter, __LINE__) = 0; always_checkf(PREPROCESSOR_JOIN(RecursionCounter, __LINE__) == 0, "Enclosing block was entered recursively."); const NAMESPACE_REDCRAFT::NAMESPACE_PRIVATE::FRecursionScopeMarker PREPROCESSOR_JOIN(ScopeMarker, __LINE__)(PREPROCESSOR_JOIN(RecursionCounter, __LINE__)) #define always_unimplemented() always_checkf(false, "Unimplemented function called.") -#if BUILD_DEBUG +#if BUILD_DEBUG || BUILD_DEVELOPMENT # define check(InExpr) always_check(InExpr) # define checkf(InExpr, InFormat, ...) always_checkf(InExpr, InFormat, ##__VA_ARGS__) diff --git a/Redcraft.Utility/Source/Public/Templates/Atomic.h b/Redcraft.Utility/Source/Public/Templates/Atomic.h index 18a71cb..55154fc 100644 --- a/Redcraft.Utility/Source/Public/Templates/Atomic.h +++ b/Redcraft.Utility/Source/Public/Templates/Atomic.h @@ -31,12 +31,12 @@ FORCEINLINE void MemoryOrderCheck(EMemoryOrder Order, uint8 Require) { switch (Order) { - case EMemoryOrder::Relaxed: checkf((Require) & 0x01, "Invalid memory order."); break; - case EMemoryOrder::Consume: checkf((Require) & 0x02, "Invalid memory order."); break; - case EMemoryOrder::Acquire: checkf((Require) & 0x04, "Invalid memory order."); break; - case EMemoryOrder::Release: checkf((Require) & 0x08, "Invalid memory order."); break; - case EMemoryOrder::AcquireRelease: checkf((Require) & 0x10, "Invalid memory order."); break; - case EMemoryOrder::SequentiallyConsistent: checkf((Require) & 0x20, "Invalid memory order."); break; + case EMemoryOrder::Relaxed: checkf((Require) & 0x01, TEXT("Invalid memory order.")); break; + case EMemoryOrder::Consume: checkf((Require) & 0x02, TEXT("Invalid memory order.")); break; + case EMemoryOrder::Acquire: checkf((Require) & 0x04, TEXT("Invalid memory order.")); break; + case EMemoryOrder::Release: checkf((Require) & 0x08, TEXT("Invalid memory order.")); break; + case EMemoryOrder::AcquireRelease: checkf((Require) & 0x10, TEXT("Invalid memory order.")); break; + case EMemoryOrder::SequentiallyConsistent: checkf((Require) & 0x20, TEXT("Invalid memory order.")); break; default: check_no_entry(); } } diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index f68418c..42ae085 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -359,7 +359,7 @@ struct TVariant constexpr auto Visit(F&& Func) & { using ReturnType = typename TCommonType::Type...>::Type; - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return ReturnType(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitLValueFuncs[GetIndex()](Forward(Func), &Value)); } @@ -367,7 +367,7 @@ struct TVariant constexpr auto Visit(F&& Func) && { using ReturnType = typename TCommonType::Type...>::Type; - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return ReturnType(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitRValueFuncs[GetIndex()](Forward(Func), &Value)); } @@ -375,7 +375,7 @@ struct TVariant constexpr auto Visit(F&& Func) const& { using ReturnType = typename TCommonType::Type...>::Type; - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return ReturnType(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitConstLValueFuncs[GetIndex()](Forward(Func), &Value)); } @@ -383,35 +383,35 @@ struct TVariant constexpr auto Visit(F&& Func) const&& { using ReturnType = typename TCommonType::Type...>::Type; - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return ReturnType(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitConstRValueFuncs[GetIndex()](Forward(Func), &Value)); } template requires (true && ... && TIsInvocableResult::Value) constexpr R Visit(F&& Func) & { - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return R(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitLValueFuncs[GetIndex()](Forward(Func), &Value)); } template requires (true && ... && TIsInvocableResult::Value) constexpr R Visit(F&& Func) && { - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return R(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitRValueFuncs[GetIndex()](Forward(Func), &Value)); } template requires (true && ... && TIsInvocableResult::Value) constexpr R Visit(F&& Func) const& { - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return R(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitConstLValueFuncs[GetIndex()](Forward(Func), &Value)); } template requires (true && ... && TIsInvocableResult::Value) constexpr R Visit(F&& Func) const&& { - checkf(IsValid(), "It is an error to call Visit() on an wrong TVariant. Please either check IsValid()."); + checkf(IsValid(), TEXT("It is an error to call Visit() on an wrong TVariant. Please either check IsValid().")); return R(NAMESPACE_PRIVATE::TVariantVisitHelper::VisitConstRValueFuncs[GetIndex()](Forward(Func), &Value)); }