From 04bd253390cc6c67a555e4837e7e48d524fdf014 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 23 Feb 2022 20:02:58 +0100 Subject: [PATCH] Move the codebase to C++14 --- CMakeLists.txt | 3 ++- android/native/jni/Application.mk | 2 +- src/CMakeLists.txt | 6 +----- src/modchannels.cpp | 3 +-- src/server.cpp | 6 +++--- src/unittest/test_address.cpp | 2 +- src/unittest/test_eventmanager.cpp | 4 ++-- src/unittest/test_server_shutdown_state.cpp | 4 +--- src/util/metricsbackend.cpp | 3 +-- 9 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1da83a99c..827191835 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,8 @@ endif() project(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(CLANG_MINIMUM_VERSION "3.5") diff --git a/android/native/jni/Application.mk b/android/native/jni/Application.mk index e21bca61c..9d9596137 100644 --- a/android/native/jni/Application.mk +++ b/android/native/jni/Application.mk @@ -20,7 +20,7 @@ APP_CPPFLAGS := -g -Og -fno-omit-frame-pointer endif 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 ifeq ($(APP_ABI),arm64-v8a) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f207244c..57baf20bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -718,7 +718,6 @@ if(MSVC) endif() else() # GCC or compatible compilers such as Clang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") if(WARN_ALL) set(RELEASE_WARNING_FLAGS "-Wall") else() @@ -751,6 +750,7 @@ else() if(MINGW) set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows") endif() # Use a safe subset of flags to speed up math calculations: @@ -787,10 +787,6 @@ else() if(USE_GPROF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") endif() - - if(MINGW) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows") - endif() endif() diff --git a/src/modchannels.cpp b/src/modchannels.cpp index 301dcb092..9626e8e0c 100644 --- a/src/modchannels.cpp +++ b/src/modchannels.cpp @@ -88,8 +88,7 @@ bool ModChannelMgr::canWriteOnChannel(const std::string &channel) const void ModChannelMgr::registerChannel(const std::string &channel) { - m_registered_channels[channel] = - std::unique_ptr(new ModChannel(channel)); + m_registered_channels[channel] = std::make_unique(channel); } bool ModChannelMgr::setChannelState(const std::string &channel, ModChannelState state) diff --git a/src/server.cpp b/src/server.cpp index 685d8bb25..d9205c895 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -254,7 +254,7 @@ Server::Server( #if USE_PROMETHEUS m_metrics_backend = std::unique_ptr(createPrometheusMetricsBackend()); #else - m_metrics_backend = std::unique_ptr(new MetricsBackend()); + m_metrics_backend = std::make_unique(); #endif 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->beginSave(); - m_modmgr = std::unique_ptr(new ServerModManager(m_path_world)); + m_modmgr = std::make_unique(m_path_world); std::vector unsatisfied_mods = m_modmgr->getUnsatisfiedMods(); // complain about mods with unsatisfied dependencies if (!m_modmgr->isConsistent()) { @@ -426,7 +426,7 @@ void Server::init() m_script = new ServerScripting(this); // Must be created before mod loading because we have some inventory creation - m_inventory_mgr = std::unique_ptr(new ServerInventoryManager()); + m_inventory_mgr = std::make_unique(); m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); diff --git a/src/unittest/test_address.cpp b/src/unittest/test_address.cpp index 35d4effb6..f46135577 100644 --- a/src/unittest/test_address.cpp +++ b/src/unittest/test_address.cpp @@ -56,7 +56,7 @@ void TestAddress::testIsLocalhost() UASSERT(!Address(172, 45, 37, 68, 0).isLocalhost()); // v6 - std::unique_ptr ipv6Bytes(new IPv6AddressBytes()); + auto ipv6Bytes = std::make_unique(); std::vector ipv6RawAddr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16); UASSERT(Address(ipv6Bytes.get(), 0).isLocalhost()) diff --git a/src/unittest/test_eventmanager.cpp b/src/unittest/test_eventmanager.cpp index bb0e59336..fec57f9fe 100644 --- a/src/unittest/test_eventmanager.cpp +++ b/src/unittest/test_eventmanager.cpp @@ -82,7 +82,7 @@ void TestEventManager::testDeregister() void TestEventManager::testRealEvent() { EventManager ev; - std::unique_ptr emt(new EventManagerTest()); + auto emt = std::make_unique(); ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get()); // Put event & verify event value @@ -93,7 +93,7 @@ void TestEventManager::testRealEvent() void TestEventManager::testRealEventAfterDereg() { EventManager ev; - std::unique_ptr emt(new EventManagerTest()); + auto emt = std::make_unique(); ev.reg(MtEvent::PLAYER_REGAIN_GROUND, EventManagerTest::eventTest, emt.get()); // Put event & verify event value diff --git a/src/unittest/test_server_shutdown_state.cpp b/src/unittest/test_server_shutdown_state.cpp index fbb76ff6a..50305e725 100644 --- a/src/unittest/test_server_shutdown_state.cpp +++ b/src/unittest/test_server_shutdown_state.cpp @@ -26,12 +26,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class FakeServer : public Server { public: - // clang-format off FakeServer() : Server("fakeworld", SubgameSpec("fakespec", "fakespec"), true, Address(), true, nullptr) { } - // clang-format on private: void SendChatMessage(session_t peer_id, const ChatMessage &message) @@ -95,7 +93,7 @@ void TestServerShutdownState::testTrigger() void TestServerShutdownState::testTick() { - std::unique_ptr fakeServer(new FakeServer()); + auto fakeServer = std::make_unique(); Server::ShutdownState ss; ss.trigger(28.0f, "testtrigger", true); ss.tick(0.0f, fakeServer.get()); diff --git a/src/util/metricsbackend.cpp b/src/util/metricsbackend.cpp index 4454557a3..c3b7def62 100644 --- a/src/util/metricsbackend.cpp +++ b/src/util/metricsbackend.cpp @@ -99,8 +99,7 @@ class PrometheusMetricsBackend : public MetricsBackend { public: PrometheusMetricsBackend(const std::string &addr) : - MetricsBackend(), m_exposer(std::unique_ptr( - new prometheus::Exposer(addr))), + MetricsBackend(), m_exposer(std::make_unique(addr)), m_registry(std::make_shared()) { m_exposer->RegisterCollectable(m_registry);