Move the codebase to C++14

This commit is contained in:
sfan5 2022-02-23 20:02:58 +01:00
parent 7db751df3b
commit 04bd253390
9 changed files with 13 additions and 20 deletions

View File

@ -11,7 +11,8 @@ endif()
project(minetest) project(minetest)
set(PROJECT_NAME_CAPITALIZED "Minetest") set(PROJECT_NAME_CAPITALIZED "Minetest")
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(GCC_MINIMUM_VERSION "5.1") set(GCC_MINIMUM_VERSION "5.1")
set(CLANG_MINIMUM_VERSION "3.5") set(CLANG_MINIMUM_VERSION "3.5")

View File

@ -20,7 +20,7 @@ APP_CPPFLAGS := -g -Og -fno-omit-frame-pointer
endif endif
APP_CFLAGS := $(APP_CPPFLAGS) -Wno-inconsistent-missing-override -Wno-parentheses-equality APP_CFLAGS := $(APP_CPPFLAGS) -Wno-inconsistent-missing-override -Wno-parentheses-equality
APP_CXXFLAGS := $(APP_CPPFLAGS) -fexceptions -frtti -std=gnu++17 APP_CXXFLAGS := $(APP_CPPFLAGS) -fexceptions -frtti -std=gnu++14
APP_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections,--icf=safe APP_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections,--icf=safe
ifeq ($(APP_ABI),arm64-v8a) ifeq ($(APP_ABI),arm64-v8a)

View File

@ -718,7 +718,6 @@ if(MSVC)
endif() endif()
else() else()
# GCC or compatible compilers such as Clang # GCC or compatible compilers such as Clang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(WARN_ALL) if(WARN_ALL)
set(RELEASE_WARNING_FLAGS "-Wall") set(RELEASE_WARNING_FLAGS "-Wall")
else() else()
@ -751,6 +750,7 @@ else()
if(MINGW) if(MINGW)
set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions") set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
endif() endif()
# Use a safe subset of flags to speed up math calculations: # Use a safe subset of flags to speed up math calculations:
@ -787,10 +787,6 @@ else()
if(USE_GPROF) if(USE_GPROF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
endif() endif()
if(MINGW)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
endif()
endif() endif()

View File

@ -88,8 +88,7 @@ bool ModChannelMgr::canWriteOnChannel(const std::string &channel) const
void ModChannelMgr::registerChannel(const std::string &channel) void ModChannelMgr::registerChannel(const std::string &channel)
{ {
m_registered_channels[channel] = m_registered_channels[channel] = std::make_unique<ModChannel>(channel);
std::unique_ptr<ModChannel>(new ModChannel(channel));
} }
bool ModChannelMgr::setChannelState(const std::string &channel, ModChannelState state) bool ModChannelMgr::setChannelState(const std::string &channel, ModChannelState state)

View File

@ -254,7 +254,7 @@ Server::Server(
#if USE_PROMETHEUS #if USE_PROMETHEUS
m_metrics_backend = std::unique_ptr<MetricsBackend>(createPrometheusMetricsBackend()); m_metrics_backend = std::unique_ptr<MetricsBackend>(createPrometheusMetricsBackend());
#else #else
m_metrics_backend = std::unique_ptr<MetricsBackend>(new MetricsBackend()); m_metrics_backend = std::make_unique<MetricsBackend>();
#endif #endif
m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)"); m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)");
@ -406,7 +406,7 @@ void Server::init()
m_mod_storage_database = openModStorageDatabase(m_path_world); m_mod_storage_database = openModStorageDatabase(m_path_world);
m_mod_storage_database->beginSave(); m_mod_storage_database->beginSave();
m_modmgr = std::unique_ptr<ServerModManager>(new ServerModManager(m_path_world)); m_modmgr = std::make_unique<ServerModManager>(m_path_world);
std::vector<ModSpec> unsatisfied_mods = m_modmgr->getUnsatisfiedMods(); std::vector<ModSpec> unsatisfied_mods = m_modmgr->getUnsatisfiedMods();
// complain about mods with unsatisfied dependencies // complain about mods with unsatisfied dependencies
if (!m_modmgr->isConsistent()) { if (!m_modmgr->isConsistent()) {
@ -426,7 +426,7 @@ void Server::init()
m_script = new ServerScripting(this); m_script = new ServerScripting(this);
// Must be created before mod loading because we have some inventory creation // Must be created before mod loading because we have some inventory creation
m_inventory_mgr = std::unique_ptr<ServerInventoryManager>(new ServerInventoryManager()); m_inventory_mgr = std::make_unique<ServerInventoryManager>();
m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);

View File

@ -56,7 +56,7 @@ void TestAddress::testIsLocalhost()
UASSERT(!Address(172, 45, 37, 68, 0).isLocalhost()); UASSERT(!Address(172, 45, 37, 68, 0).isLocalhost());
// v6 // v6
std::unique_ptr<IPv6AddressBytes> ipv6Bytes(new IPv6AddressBytes()); auto ipv6Bytes = std::make_unique<IPv6AddressBytes>();
std::vector<u8> ipv6RawAddr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; std::vector<u8> ipv6RawAddr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16); memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16);
UASSERT(Address(ipv6Bytes.get(), 0).isLocalhost()) UASSERT(Address(ipv6Bytes.get(), 0).isLocalhost())

View File

@ -82,7 +82,7 @@ void TestEventManager::testDeregister()
void TestEventManager::testRealEvent() void TestEventManager::testRealEvent()
{ {
EventManager ev; EventManager ev;
std::unique_ptr<EventManagerTest> emt(new EventManagerTest()); auto emt = std::make_unique<EventManagerTest>();
ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get()); ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get());
// Put event & verify event value // Put event & verify event value
@ -93,7 +93,7 @@ void TestEventManager::testRealEvent()
void TestEventManager::testRealEventAfterDereg() void TestEventManager::testRealEventAfterDereg()
{ {
EventManager ev; EventManager ev;
std::unique_ptr<EventManagerTest> emt(new EventManagerTest()); auto emt = std::make_unique<EventManagerTest>();
ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get()); ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get());
// Put event & verify event value // Put event & verify event value

View File

@ -26,12 +26,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class FakeServer : public Server class FakeServer : public Server
{ {
public: public:
// clang-format off
FakeServer() : Server("fakeworld", SubgameSpec("fakespec", "fakespec"), true, FakeServer() : Server("fakeworld", SubgameSpec("fakespec", "fakespec"), true,
Address(), true, nullptr) Address(), true, nullptr)
{ {
} }
// clang-format on
private: private:
void SendChatMessage(session_t peer_id, const ChatMessage &message) void SendChatMessage(session_t peer_id, const ChatMessage &message)
@ -95,7 +93,7 @@ void TestServerShutdownState::testTrigger()
void TestServerShutdownState::testTick() void TestServerShutdownState::testTick()
{ {
std::unique_ptr<FakeServer> fakeServer(new FakeServer()); auto fakeServer = std::make_unique<FakeServer>();
Server::ShutdownState ss; Server::ShutdownState ss;
ss.trigger(28.0f, "testtrigger", true); ss.trigger(28.0f, "testtrigger", true);
ss.tick(0.0f, fakeServer.get()); ss.tick(0.0f, fakeServer.get());

View File

@ -99,8 +99,7 @@ class PrometheusMetricsBackend : public MetricsBackend
{ {
public: public:
PrometheusMetricsBackend(const std::string &addr) : PrometheusMetricsBackend(const std::string &addr) :
MetricsBackend(), m_exposer(std::unique_ptr<prometheus::Exposer>( MetricsBackend(), m_exposer(std::make_unique<prometheus::Exposer>(addr)),
new prometheus::Exposer(addr))),
m_registry(std::make_shared<prometheus::Registry>()) m_registry(std::make_shared<prometheus::Registry>())
{ {
m_exposer->RegisterCollectable(m_registry); m_exposer->RegisterCollectable(m_registry);