Browse Source

Move the codebase to C++14

sfan5 2 years ago
parent
commit
04bd253390

+ 2 - 1
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")
 

+ 1 - 1
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)

+ 1 - 5
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()
 
 

+ 1 - 2
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<ModChannel>(new ModChannel(channel));
+	m_registered_channels[channel] = std::make_unique<ModChannel>(channel);
 }
 
 bool ModChannelMgr::setChannelState(const std::string &channel, ModChannelState state)

+ 3 - 3
src/server.cpp

@@ -254,7 +254,7 @@ Server::Server(
 #if USE_PROMETHEUS
 	m_metrics_backend = std::unique_ptr<MetricsBackend>(createPrometheusMetricsBackend());
 #else
-	m_metrics_backend = std::unique_ptr<MetricsBackend>(new MetricsBackend());
+	m_metrics_backend = std::make_unique<MetricsBackend>();
 #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<ServerModManager>(new ServerModManager(m_path_world));
+	m_modmgr = std::make_unique<ServerModManager>(m_path_world);
 	std::vector<ModSpec> 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<ServerInventoryManager>(new ServerInventoryManager());
+	m_inventory_mgr = std::make_unique<ServerInventoryManager>();
 
 	m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
 

+ 1 - 1
src/unittest/test_address.cpp

@@ -56,7 +56,7 @@ void TestAddress::testIsLocalhost()
 	UASSERT(!Address(172, 45, 37, 68, 0).isLocalhost());
 
 	// 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};
 	memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16);
 	UASSERT(Address(ipv6Bytes.get(), 0).isLocalhost())

+ 2 - 2
src/unittest/test_eventmanager.cpp

@@ -82,7 +82,7 @@ void TestEventManager::testDeregister()
 void TestEventManager::testRealEvent()
 {
 	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());
 
 	// Put event & verify event value
@@ -93,7 +93,7 @@ void TestEventManager::testRealEvent()
 void TestEventManager::testRealEventAfterDereg()
 {
 	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());
 
 	// Put event & verify event value

+ 1 - 3
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> fakeServer(new FakeServer());
+	auto fakeServer = std::make_unique<FakeServer>();
 	Server::ShutdownState ss;
 	ss.trigger(28.0f, "testtrigger", true);
 	ss.tick(0.0f, fakeServer.get());

+ 1 - 2
src/util/metricsbackend.cpp

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