Download

[solved] checkf and UTF8_TO_TCHAR error: static_assert failed "Formatting string must be a TCHAR array."

I have something like this which works on 4.18, but not on 4.19:



#define     CRYPTO_UNKNOWN_ERROR                      "RCrypto: unknown error!"

.
.
.

    catch (const std::exception& ex) {
#if defined ( _WIN32 ) || defined ( _WIN64 )
        MessageBoxA(0, ex.what(), "Cryptography Error", MB_OK);
#endif  /* defined ( _WIN32 ) || defined ( _WIN64 ) */
        checkf(false, UTF8_TO_TCHAR(ex.what()));
    }

    catch (...) {
#if defined ( _WIN32 ) || defined ( _WIN64 )
        MessageBoxA(0, CRYPTO_UNKNOWN_ERROR, "Cryptography Error", MB_OK);
#endif  /* defined ( _WIN32 ) || defined ( _WIN64 ) */
        checkf(false, UTF8_TO_TCHAR(CRYPTO_UNKNOWN_ERROR));
    }


And here is the error with both checkfs:



Runtime/Core/Public/Misc/AssertionMacros.h:50:3: error: static_assert failed "Formatting string must be a TCHAR array."

static_assert(TIsArrayOrRefOfType<FmtType, TCHAR>::Value, "Formatting string must be a TCHAR array.");


Looking at UTF8_TO_TCHAR definition, I assume it should return a TCHAR* as expected:



#define UTF8_TO_TCHAR(str) (TCHAR*)FUTF8ToTCHAR((const ANSICHAR*)str).Get()


Well, looking at Mist/AssersionMacros.h it seems that it went through a major overhaul for 4.19.



#define checkf(expr, format,  ...)


As the assertion says it required a formatting string for the second argument which must be a TCHAR array not a TCHAR pointer.

Thus, the correct way of calling it must be something like this:



/// All work

       checkf(false, TEXT("A wide char string literal"))
// or
       checkf(false, TEXT("%s"), UTF8_TO_TCHAR(ex.what()));
// or
       FString myString("A wide char string");
       checkf(false, TEXT("%s"), myString.GetCharArray().GetData());


None of these cases work any more:



/// Results in build errors

checkf(false, UTF8_TO_TCHAR(ex.what()));
// or
FString myString("A wide char string");
checkf(false, myString.GetCharArray().GetData());


This has not been documented in the documentation source on Github yet, hope they update the documentation soon.