Skip to content

Commit 651bef0

Browse files
committed
Fix #2415 c++23 compile error
1 parent 6f4da00 commit 651bef0

File tree

10 files changed

+34
-21
lines changed

10 files changed

+34
-21
lines changed

1k/1kiss.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,10 @@ if (!$setupOnly) {
18591859
$CONFIG_ALL_OPTIONS = @()
18601860
}
18611861

1862+
if ($env:__1K_CXXSTD) {
1863+
$CONFIG_ALL_OPTIONS += "-DCMAKE_CXX_STANDARD=$env:__1K_CXXSTD"
1864+
}
1865+
18621866
if ($options.u) {
18631867
$CONFIG_ALL_OPTIONS += '-D_1KFETCH_UPGRADE=TRUE'
18641868
}

cmake/Modules/AXConfigDefine.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ if (CMAKE_CXX_STANDARD GREATER_EQUAL ${_AX_MIN_CXX_STD})
6464
else()
6565
message(STATUS "Building axmol require c++ std >= ${_AX_MIN_CXX_STD}")
6666
endif()
67+
68+
# used to set 3rdparty c++ standard same with axmol
6769
set(_AX_CXX_STD ${CMAKE_CXX_STANDARD} CACHE STRING "" FORCE)
6870

6971
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)

core/audio/AudioPlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <condition_variable>
3333
#include <mutex>
3434
#include <thread>
35+
#include <atomic>
3536

3637
#include "audio/AudioMacros.h"
3738
#include "platform/PlatformMacros.h"

core/base/Logging.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ AX_API void setLogOutput(ILogOutput* output)
6868
s_logOutput = output;
6969
}
7070

71-
AX_API LogItem& preprocessLog(LogItem&& item)
71+
AX_API LogItem&& preprocessLog(LogItem&& item)
7272
{
7373
if (s_logFmtFlags != LogFmtFlag::Null)
7474
{
@@ -147,8 +147,7 @@ AX_API LogItem& preprocessLog(LogItem&& item)
147147
prefix_size += fmt::format_to_n(wptr + prefix_size, buffer_size - prefix_size,
148148
"[{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:03d}]", ts.tm_year + 1900,
149149
ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec,
150-
static_cast<int>(tv_msec % std::milli::den))
151-
.size;
150+
static_cast<int>(tv_msec % std::milli::den)).size;
152151
}
153152
if (bitmask::any(s_logFmtFlags, LogFmtFlag::ProcessId))
154153
prefix_size +=
@@ -157,13 +156,15 @@ AX_API LogItem& preprocessLog(LogItem&& item)
157156
prefix_size +=
158157
fmt::format_to_n(wptr + prefix_size, buffer_size - prefix_size, "[TID:{:x}]", xmol_gettid()).size;
159158
}
160-
return item;
159+
return std::forward<LogItem>(item);
161160
}
162161

163-
AX_DLL void outputLog(LogItem& item, const char* tag)
162+
AX_DLL void outputLog(LogItem&& item, const char* tag)
164163
{
165-
if (!s_logOutput) writeLog(item, tag);
166-
else s_logOutput->write(item, tag);
164+
if (!s_logOutput)
165+
writeLog(item, tag);
166+
else
167+
s_logOutput->write(item, tag);
167168
}
168169

169170
AX_DLL void writeLog(LogItem& item, const char* tag)
@@ -210,7 +211,7 @@ AX_DLL void writeLog(LogItem& item, const char* tag)
210211
OutputDebugStringW(ntcvt::from_chars(item.message()).c_str());
211212
# endif
212213

213-
// write normal color text to console
214+
// write normal color text to console
214215
# if defined(_WIN32)
215216
auto hStdout = ::GetStdHandle(item.level_ != LogLevel::Error ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
216217
if (hStdout)
@@ -244,4 +245,4 @@ AX_API void print(const char* format, ...)
244245
"axmol debug info");
245246
}
246247
#endif
247-
}
248+
} // namespace ax

core/base/Logging.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ AX_ENABLE_BITMASK_OPS(LogFmtFlag);
5757

5858
class LogItem
5959
{
60-
friend AX_API LogItem& preprocessLog(LogItem&& logItem);
60+
friend AX_API LogItem&& preprocessLog(LogItem&& logItem);
6161
friend AX_API void writeLog(LogItem& item, const char* tag);
6262

6363
public:
@@ -77,7 +77,7 @@ class LogItem
7777
}
7878

7979
template <typename _FmtType, typename... _Types>
80-
inline static LogItem& vformat(_FmtType&& fmt, LogItem& item, _Types&&... args)
80+
inline static LogItem&& vformat(_FmtType&& fmt, LogItem&& item, _Types&&... args)
8181
{
8282
item.qualified_message_ =
8383
fmt::format(std::forward<_FmtType>(fmt), std::string_view{item.prefix_buffer_, item.prefix_size_},
@@ -89,7 +89,7 @@ class LogItem
8989
if (item.has_style_)
9090
item.qualified_message_.append("\x1b[m"sv);
9191
item.qualifier_size_ += (item.qualified_message_.size() - old_size);
92-
return item;
92+
return std::forward<LogItem>(item);
9393
}
9494

9595
private:
@@ -124,17 +124,19 @@ AX_API void setLogFmtFlag(LogFmtFlag flags);
124124
AX_API void setLogOutput(ILogOutput* output);
125125

126126
/* @brief internal use */
127-
AX_API LogItem& preprocessLog(LogItem&& logItem);
127+
AX_API LogItem&& preprocessLog(LogItem&& logItem);
128128

129129
/* @brief internal use */
130-
AX_API void outputLog(LogItem& item, const char* tag);
130+
AX_API void outputLog(LogItem&& item, const char* tag);
131131
AX_API void writeLog(LogItem& item, const char* tag);
132132

133133
template <typename _FmtType, typename... _Types>
134-
inline void printLogT(_FmtType&& fmt, LogItem& item, _Types&&... args)
134+
inline void printLogT(_FmtType&& fmt, LogItem&& item, _Types&&... args)
135135
{
136136
if (item.level() >= getLogLevel())
137-
outputLog(LogItem::vformat(std::forward<_FmtType>(fmt), item, std::forward<_Types>(args)...), "axmol");
137+
outputLog(
138+
LogItem::vformat(std::forward<_FmtType>(fmt), std::forward<LogItem>(item), std::forward<_Types>(args)...),
139+
"axmol");
138140
}
139141

140142
#define AXLOG_WITH_LEVEL(level, fmtOrMsg, ...) \
@@ -158,12 +160,12 @@ inline void printLogT(_FmtType&& fmt, LogItem& item, _Types&&... args)
158160
#define AXLOGW(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Warn, fmtOrMsg, ##__VA_ARGS__)
159161
#define AXLOGE(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Error, fmtOrMsg, ##__VA_ARGS__)
160162

161-
#define AXLOGT AXLOGV
163+
#define AXLOGT AXLOGV
162164

163165
#ifndef AX_CORE_PROFILE
164166
/**
165167
@brief Output Debug message.
166168
*/
167169
/* AX_DEPRECATED(2.1)*/ AX_API void print(const char* format, ...) AX_FORMAT_PRINTF(1, 2); // use AXLOGD instead
168170
#endif
169-
}
171+
} // namespace ax

core/base/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ std::string urlDecode(std::string_view st)
829829
return decoded;
830830
}
831831

832-
AX_DLL std::string& filePathToUrl(std::string&& path)
832+
AX_DLL std::string&& filePathToUrl(std::string&& path)
833833
{
834834
//
835835
// file uri helper: https://www.ietf.org/rfc/rfc3986.txt
@@ -857,7 +857,7 @@ AX_DLL std::string& filePathToUrl(std::string&& path)
857857
#endif
858858
}
859859
}
860-
return path;
860+
return std::forward<std::string>(path);
861861
}
862862

863863
AX_DLL std::string base64Encode(const void* in, size_t inlen)

core/base/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ AX_DLL std::string urlEncode(std::string_view s);
424424

425425
AX_DLL std::string urlDecode(std::string_view st);
426426

427-
AX_DLL std::string& filePathToUrl(std::string&& path);
427+
AX_DLL std::string&& filePathToUrl(std::string&& path);
428428

429429
/**
430430
* Encodes bytes into a 64base buffer

core/media/VlcMediaEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#if defined(AX_ENABLE_VLC_MEDIA)
1010

1111
#include "vlc/vlc.h"
12+
#include <atomic>
1213

1314
namespace ax
1415
{

core/network/Downloader-curl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
# include <curl/curl.h>
3434
# include <thread>
35+
# include <atomic>
3536
# include "base/Utils.h"
3637
# include "base/UTF8.h"
3738
# include "base/Director.h"

core/network/HttpRequest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <vector>
3333
#include <memory>
3434
#include <future>
35+
#include <atomic>
3536
#include "base/Object.h"
3637
#include "base/Macros.h"
3738

0 commit comments

Comments
 (0)