I'm trying to make a game debugger with limited warnings (if possible no warnings and suppressed warnings).
While creating a message interface class, I kept getting this warning: "Warning C4710 'IMessageA::IMessageA(IMessageType,size_t,const char *,...)': function not inlined Game Logger Game Logger\Source.cpp 256"
I know I could suppress the warning, but I would prefer to fix it then suppress it. I tried "__forceinline", "__inline", and "inline" but the compiler warning didn't go away.
enum class IMessageType
{
IMessageType_Message,
IMessageType_Info,
IMessageType_Warning,
IMessageType_Debug,
IMessageType_Error,
IMessageType_FatalError
};
enum class IMessageSource
{
IMessageSource_None,
IMessageSource_User,
IMessageSource_Internal,
IMessageSource_External,
IMessageSource_Unknown
};
class IMessageA : public std::string
{
public:
IMessageA(IMessageType Type, IMessageSource Source, const char* Caller, const char* File,
const char* Func, int Line, size_t Words, const char* Format, ...)
{
_Type = Type;
const char* MessageType = FormatMessageType(_Type);
_Source = Source;
const char* MessageSource = FormatMessageSource(_Source);
_Caller = Caller;
_File = File;
_Func = Func;
_Line = Line;
time_t MessageTime = 0;
time(&MessageTime);
tm MessgeDateStamp = { 0 };
localtime_s(&MessgeDateStamp, &MessageTime);
char MessageTimeStamp[26] = { 0 };
asctime_s(&MessageTimeStamp[0], 26, &MessgeDateStamp);
std::unique_ptr<char[]> FormattedMessage = std::make_unique<char[]>(Words + 1);
va_list _Args = nullptr;
__crt_va_start(_Args, Format);
_vsnprintf_s(FormattedMessage.get(), Words, Words, Format, _Args);
_Args = nullptr;
this->operator+=("[");
this->operator+=(&MessageTimeStamp[0]);
this->pop_back();
this->operator+=("][");
if (MessageSource != nullptr)
{
this->operator+=(&MessageSource[0]);
}
if (MessageSource != nullptr && _Caller != nullptr)
{
this->operator+=(": ");
}
if (_Caller != nullptr)
{
this->operator+=(_Caller);
this->operator+=("][");
}
this->operator+=(MessageType);
this->operator+=("] ");
if (_Func != nullptr)
{
this->operator+=(_Func);
this->operator+=(" - ");
}
if (_File != nullptr)
{
this->operator+=(_File);
this->operator+=(": ");
}
if (_Line != 0)
{
this->operator+=("Line: ");
this->operator+=(std::to_string(_Line));
this->operator+=(" - ");
}
if (FormattedMessage != nullptr)
{
this->operator+=(FormattedMessage.get());
}
FormattedMessage.release();
}
IMessageA(IMessageType Type, size_t Words, const char* Format, ...)
{
_Type = Type;
const char* MessageType = FormatMessageType(_Type);
time_t MessageTime = 0;
time(&MessageTime);
tm MessgeDateStamp = { 0 };
localtime_s(&MessgeDateStamp, &MessageTime);
char MessageTimeStamp[26] = { 0 };
asctime_s(&MessageTimeStamp[0], 26, &MessgeDateStamp);
std::unique_ptr<char[]> FormattedMessage = std::make_unique<char[]>(Words + 1);
va_list _Args = nullptr;
__crt_va_start(_Args, Format);
_vsnprintf_s(FormattedMessage.get(), Words, Words, Format, _Args);
_Args = nullptr;
this->operator+=("[");
this->operator+=(&MessageTimeStamp[0]);
this->pop_back();
this->operator+=("][");
this->operator+=(MessageType);
this->operator+=("] ");
if (FormattedMessage != nullptr)
{
this->operator+=(FormattedMessage.get());
}
FormattedMessage.release();
}
private:
_Check_return_ const char* FormatMessageType(IMessageType Type) noexcept
{
switch (Type)
{
case IMessageType::IMessageType_Message:
return "_MSG_";
case IMessageType::IMessageType_Info:
return "_INFO";
case IMessageType::IMessageType_Warning:
return "_WARN";
case IMessageType::IMessageType_Debug:
return "DEBUG";
case IMessageType::IMessageType_Error:
return "ERROR";
case IMessageType::IMessageType_FatalError:
return "FATAL";
}
return "UKNWN";
}
_Check_return_ const char* FormatMessageSource(IMessageSource Source) noexcept
{
switch (Source)
{
case IMessageSource::IMessageSource_User:
return "__USER__";
case IMessageSource::IMessageSource_Internal:
return "INTERNAL";
case IMessageSource::IMessageSource_External:
return "EXTERNAL";
case IMessageSource::IMessageSource_Unknown:
return "UNKNOWN_";
case IMessageSource::IMessageSource_None:
return nullptr;
}
return nullptr;
}
protected:
IMessageType _Type = IMessageType::IMessageType_Message;
IMessageSource _Source = IMessageSource::IMessageSource_Internal;
const char* _Caller = nullptr;
const char* _File = nullptr;
const char* _Func = nullptr;
int _Line = 0;
long _Reserved = 0;
};
Not sure if it's important, but I will include some extra data:
C++ Language Standard: ISO C++20 Standard (/std:c++20) C Language Standard: ISO C17 (2018) Standard (/std:c17) Warning Level: EnableAllWarnings (/Wall) Treat Warnings As Errors: Yes (/WX) And I set all of the C++ programmer rule sets to active to make sure I don't miss anything.