fmt – Formatting of non-void pointers is disallowed

  Kiến thức lập trình

This code:

#pragma once

#include <fmt/format.h>

template <typename EnumType>
requires std::is_enum_v<EnumType>
struct fmt::formatter<EnumType> : fmt::formatter<std::underlying_type_t<EnumType>>
{
    // Forwards the formatting by casting the enum to its underlying type
    auto format(const EnumType& enumValue, fmt::format_context& ctx) const
    {
        return fmt::formatter<std::underlying_type_t<EnumType>>::format(
                static_cast<std::underlying_type_t<EnumType>>(enumValue), ctx);
    }
};

template<typename Format, typename... Args>
inline std::string StringFormat(Format&& fmt, Args&&... args)
{
    try
    {
        if constexpr (std::is_same_v<std::decay_t<Format>, char*> || std::is_same_v<std::decay_t<Format>, const char*>)
        {
            // When format string is not known at compile-time
            return fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...);
        }
        else
        {
            // When format string is known at compile-time
            return fmt::format(std::forward<Format>(fmt), std::forward<Args>(args)...);
        }
    }
    catch (const fmt::format_error& formatError)
    {
        std::string error = "An error occurred formatting string "" + std::string(fmt) + "" : " + std::string(formatError.what());
        return error;
    }
}

/// Returns true if the given char pointer is null.
inline bool IsFormatEmptyOrNull(char const* fmt)
{
    return fmt == nullptr;
}

/// Returns true if the given std::string is empty.
inline bool IsFormatEmptyOrNull(std::string const& fmt)
{
    return fmt.empty();
}

Gives me the following error:

In file included from V:/Vibranium-Core/dep/Vibranium-Engine/Utils/StringFormat.h:7:
In file included from V:/Vibranium-Core/dep/Vibranium-Engine/dep/fmt/include/fmt/format.h:56:
V:/Vibranium-Core/dep/Vibranium-Engine/dep/fmt/include/fmt/base.h:1621:17: error: static assertion failed due to requirement 'formattable_pointer': Formatting of non-void pointers is disallowed.
 1621 |   static_assert(formattable_pointer,
      |                 ^~~~~~~~~~~~~~~~~~~
V:/Vibranium-Core/dep/Vibranium-Engine/dep/fmt/include/fmt/base.h:2004:20: note: in instantiation of function template specialization 'fmt::detail::make_arg<true, fmt::context, const wchar_t *, 0>' requested here
 2004 |   return {{detail::make_arg<NUM_ARGS <= detail::max_packed_args, Context>(
      |                    ^
V:/Vibranium-Core/dep/Vibranium-Engine/dep/fmt/include/fmt/format.h:4354:28: note: in instantiation of function template specialization 'fmt::make_format_args<fmt::context, const wchar_t *, 1ULL, 0ULL, 15ULL, 0>' requested here
 4354 |   return vformat(fmt, fmt::make_format_args(args...));
      |                            ^
V:/Vibranium-Core/dep/Vibranium-Engine/Utils/StringFormat.h:29:25: note: in instantiation of function template specialization 'fmt::format<const wchar_t *>' requested here
   29 |             return fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...);
      |                         ^
V:/Vibranium-Core/dep/Vibranium-Engine/Logging/Log.h:70:35: note: in instantiation of function template specialization 'StringFormat<const char (&)[37], const wchar_t *>' requested here
   70 |         outMessage(filter, level, StringFormat(std::forward<Format>(fmt), std::forward<Args>(args)...));
      |                                   ^
V:Vibranium-CoreSourceAuthServerMain.cpp:67:9: note: in instantiation of function template specialization 'Log::outMessage<const char (&)[37], const wchar_t *>' requested here
   67 |         LOG_ERROR("[AS] Error in configuration file: {}", config_file.c_str());
      |         ^
V:/Vibranium-Core/dep/Vibranium-Engine/Logging/Log.h:197:5: note: expanded from macro 'LOG_ERROR'
  197 |     LOG_MESSAGE_BODY("", LOG_LEVEL_ERROR, __VA_ARGS__)
      |     ^
V:/Vibranium-Core/dep/Vibranium-Engine/Logging/Log.h:160:18: note: expanded from macro 'LOG_MESSAGE_BODY'
  160 |                         LOG_EXCEPTION_FREE(filterType__, level__, __VA_ARGS__); 
      |                         ^
V:/Vibranium-Core/dep/Vibranium-Engine/Logging/Log.h:136:19: note: expanded from macro 'LOG_EXCEPTION_FREE'
  136 |             sLog->outMessage(filterType__, level__, __VA_ARGS__); 
      |                   ^
6 warnings and 1 error generated.
mingw32-make[3]: *** [SourceAuthServerCMakeFilesAuthServer.dirbuild.make:136: Source/AuthServer/CMakeFiles/AuthServer.dir/Main.cpp.obj] Error 1
mingw32-make[3]: *** Waiting for unfinished jobs....
9 warnings generated.
6 warnings generated.
mingw32-make[2]: *** [CMakeFilesMakefile2:1955: Source/AuthServer/CMakeFiles/AuthServer.dir/all] Error 2
mingw32-make[1]: *** [CMakeFilesMakefile2:1962: Source/AuthServer/CMakeFiles/AuthServer.dir/rule] Error 2
mingw32-make: *** [Makefile:740: AuthServer] Error 2

why do I get this error and how can I fix it?

4

LEAVE A COMMENT