Use std::make_unique (fixes #5166)

No idea why clang-tidy's modernize-... didn't work
This commit is contained in:
def 2022-05-28 14:46:53 +02:00
parent 73a099885b
commit 19dcd44fbe
7 changed files with 17 additions and 16 deletions

View file

@ -3008,6 +3008,7 @@ foreach(target ${TARGETS_OWN})
if((CMAKE_VERSION VERSION_GREATER 3.1 OR CMAKE_VERSION VERSION_EQUAL 3.1))
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS OFF)
endif()
if(MSVC)

View file

@ -162,7 +162,7 @@ public:
};
std::unique_ptr<ILogger> log_logger_android()
{
return std::unique_ptr<ILogger>(new CLoggerAndroid());
return std::make_unique<CLoggerAndroid>();
}
#else
std::unique_ptr<ILogger> log_logger_android()
@ -199,7 +199,7 @@ public:
std::unique_ptr<ILogger> log_logger_collection(std::vector<std::shared_ptr<ILogger>> &&loggers)
{
return std::unique_ptr<ILogger>(new CLoggerCollection(std::move(loggers)));
return std::make_unique<CLoggerCollection>(std::move(loggers));
}
class CLoggerAsync : public ILogger
@ -261,7 +261,7 @@ public:
std::unique_ptr<ILogger> log_logger_file(IOHANDLE logfile)
{
return std::unique_ptr<ILogger>(new CLoggerAsync(logfile, false, true));
return std::make_unique<CLoggerAsync>(logfile, false, true);
}
#if defined(CONF_FAMILY_WINDOWS)
@ -372,17 +372,17 @@ std::unique_ptr<ILogger> log_logger_stdout()
// TODO: Only enable true color when COLORTERM contains "truecolor".
// https://github.com/termstandard/colors/tree/65bf0cd1ece7c15fa33a17c17528b02c99f1ae0b#checking-for-colorterm
const bool colors = getenv("NO_COLOR") == nullptr && isatty(STDOUT_FILENO);
return std::unique_ptr<ILogger>(new CLoggerAsync(io_stdout(), colors, false));
return std::make_unique<CLoggerAsync>(io_stdout(), colors, false);
#else
if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == FILE_TYPE_UNKNOWN)
AttachConsole(ATTACH_PARENT_PROCESS);
HANDLE pOutput = GetStdHandle(STD_OUTPUT_HANDLE);
switch(GetFileType(pOutput))
{
case FILE_TYPE_CHAR: return std::unique_ptr<ILogger>(new CWindowsConsoleLogger(pOutput));
case FILE_TYPE_CHAR: return std::make_unique<CWindowsConsoleLogger>(pOutput);
case FILE_TYPE_PIPE: // fall through, writing to pipe works the same as writing to a file
case FILE_TYPE_DISK: return std::unique_ptr<ILogger>(new CWindowsFileLogger(pOutput));
default: return std::unique_ptr<ILogger>(new CLoggerAsync(io_stdout(), false, false));
case FILE_TYPE_DISK: return std::make_unique<CWindowsFileLogger>(pOutput);
default: return std::make_unique<CLoggerAsync>(io_stdout(), false, false);
}
#endif
}
@ -400,7 +400,7 @@ public:
};
std::unique_ptr<ILogger> log_logger_windows_debugger()
{
return std::unique_ptr<ILogger>(new CLoggerWindowsDebugger());
return std::make_unique<CLoggerWindowsDebugger>();
}
#else
std::unique_ptr<ILogger> log_logger_windows_debugger()

View file

@ -713,7 +713,7 @@ std::unique_ptr<IDbConnection> CreateMysqlConnection(
int Port,
bool Setup)
{
return std::unique_ptr<IDbConnection>(new CMysqlConnection(pDatabase, pPrefix, pUser, pPass, pIp, Port, Setup));
return std::make_unique<CMysqlConnection>(pDatabase, pPrefix, pUser, pPass, pIp, Port, Setup);
}
#else
int MysqlInit()

View file

@ -387,5 +387,5 @@ bool CSqliteConnection::AddPoints(const char *pPlayer, int Points, char *pError,
std::unique_ptr<IDbConnection> CreateSqliteConnection(const char *pFilename, bool Setup)
{
return std::unique_ptr<IDbConnection>(new CSqliteConnection(pFilename, Setup));
return std::make_unique<CSqliteConnection>(pFilename, Setup);
}

View file

@ -3908,7 +3908,7 @@ int main(int argc, const char **argv)
dbg_msg("client", "failed to open '%s' for logging", g_Config.m_Logfile);
}
}
pEngine->SetAdditionalLogger(std::unique_ptr<ILogger>(new CServerLogger(pServer)));
pEngine->SetAdditionalLogger(std::make_unique<CServerLogger>(pServer));
// run the server
dbg_msg("server", "starting...");

View file

@ -77,5 +77,5 @@ std::unique_ptr<ILogger> CreateAssertionLogger(IStorage *pStorage, const char *p
{
char aAssertLogPath[IO_MAX_PATH_LENGTH];
pStorage->GetCompletePath(IStorage::TYPE_SAVE, "dumps/", aAssertLogPath, sizeof(aAssertLogPath));
return std::unique_ptr<ILogger>(new CAssertionLogger(aAssertLogPath, pGameName));
return std::make_unique<CAssertionLogger>(aAssertLogPath, pGameName);
}

View file

@ -154,14 +154,14 @@ public:
inline std::unique_ptr<CHttpRequest> HttpHead(const char *pUrl)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->Head();
return pResult;
}
inline std::unique_ptr<CHttpRequest> HttpGet(const char *pUrl)
{
return std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
return std::make_unique<CHttpRequest>(pUrl);
}
inline std::unique_ptr<CHttpRequest> HttpGetFile(const char *pUrl, IStorage *pStorage, const char *pOutputFile, int StorageType)
@ -174,14 +174,14 @@ inline std::unique_ptr<CHttpRequest> HttpGetFile(const char *pUrl, IStorage *pSt
inline std::unique_ptr<CHttpRequest> HttpPost(const char *pUrl, const unsigned char *pData, size_t DataLength)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->Post(pData, DataLength);
return pResult;
}
inline std::unique_ptr<CHttpRequest> HttpPostJson(const char *pUrl, const char *pJson)
{
std::unique_ptr<CHttpRequest> pResult = std::unique_ptr<CHttpRequest>(new CHttpRequest(pUrl));
auto pResult = std::make_unique<CHttpRequest>(pUrl);
pResult->PostJson(pJson);
return pResult;
}