diff --git a/source/graphics/CinemaManager.cpp b/source/graphics/CinemaManager.cpp index 6b12743ffa..76a13b642b 100644 --- a/source/graphics/CinemaManager.cpp +++ b/source/graphics/CinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -76,7 +76,7 @@ void CCinemaManager::DrawPaths() const if (!cmpCinemaManager) return; - for (const std::pair& p : cmpCinemaManager->GetPaths()) + for (const std::pair& p : cmpCinemaManager->GetPaths()) { DrawSpline(p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 128, true); DrawNodes(p.second, CColor(0.1f, 1.f, 0.f, 1.f)); diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index 73f39088dc..254163da91 100644 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -46,7 +46,7 @@ CObjectEntry::CObjectEntry(CObjectBase* base, CSimulation2& simulation) : CObjectEntry::~CObjectEntry() { - for (const std::pair& anim : m_Animations) + for (const std::pair& anim : m_Animations) delete anim.second; delete m_Model; diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index 276e094b4b..43e3c9b8f3 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -170,11 +170,11 @@ void CObjectManager::DeleteObject(CObjectEntry* entry) void CObjectManager::UnloadObjects() { - for (const std::pair& p : m_Objects) + for (const std::pair& p : m_Objects) delete p.second; m_Objects.clear(); - for (const std::pair& p : m_ObjectBases) + for (const std::pair& p : m_ObjectBases) delete p.second; m_ObjectBases.clear(); } diff --git a/source/graphics/TerrainTextureManager.cpp b/source/graphics/TerrainTextureManager.cpp index 61f3c9b6ac..d4b1a0c2fa 100644 --- a/source/graphics/TerrainTextureManager.cpp +++ b/source/graphics/TerrainTextureManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -63,7 +63,7 @@ void CTerrainTextureManager::UnloadTerrainTextures() delete te; m_TextureEntries.clear(); - for (const std::pair& tg : m_TerrainGroups) + for (const std::pair& tg : m_TerrainGroups) delete tg.second; m_TerrainGroups.clear(); diff --git a/source/graphics/Unit.cpp b/source/graphics/Unit.cpp index c4cb229e27..9f66973ad8 100644 --- a/source/graphics/Unit.cpp +++ b/source/graphics/Unit.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -90,7 +90,7 @@ void CUnit::SetEntitySelection(const CStr& key, const CStr& selection) void CUnit::SetEntitySelection(const std::map& selections) { - for (const std::pair& s : selections) + for (const std::pair& s : selections) m_EntitySelections[s.first] = s.second.LowerCase(); ReloadObject(); @@ -105,7 +105,7 @@ void CUnit::SetActorSelections(const std::set& selections) void CUnit::ReloadObject() { std::set entitySelections; - for (const std::pair& selection : m_EntitySelections) + for (const std::pair& selection : m_EntitySelections) entitySelections.insert(selection.second); std::vector > selections; selections.push_back(entitySelections); diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 71177aa314..7434694c86 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -79,10 +79,10 @@ CGUI::CGUI(const shared_ptr& context) CGUI::~CGUI() { - for (const std::pair& p : m_pAllObjects) + for (const std::pair& p : m_pAllObjects) delete p.second; - for (const std::pair& p : m_Sprites) + for (const std::pair& p : m_Sprites) delete p.second; } diff --git a/source/gui/ObjectBases/IGUIObject.cpp b/source/gui/ObjectBases/IGUIObject.cpp index a5020ed3d8..f7d3d24504 100644 --- a/source/gui/ObjectBases/IGUIObject.cpp +++ b/source/gui/ObjectBases/IGUIObject.cpp @@ -74,7 +74,7 @@ IGUIObject::IGUIObject(CGUI& pGUI) IGUIObject::~IGUIObject() { - for (const std::pair& p : m_Settings) + for (const std::pair& p : m_Settings) delete p.second; if (!m_ScriptHandlers.empty()) @@ -282,7 +282,7 @@ bool IGUIObject::ApplyStyle(const CStr& StyleName) // Other styles are reported if they specify a Setting that does not exist, // so that the XML author is informed and can correct the style. - for (const std::pair& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) + for (const std::pair& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) { if (SettingExists(p.first)) SetSettingFromString(p.first, p.second, true); diff --git a/source/gui/ObjectTypes/CDropDown.cpp b/source/gui/ObjectTypes/CDropDown.cpp index 844000f021..ee4feb9d8b 100644 --- a/source/gui/ObjectTypes/CDropDown.cpp +++ b/source/gui/ObjectTypes/CDropDown.cpp @@ -304,11 +304,11 @@ InReaction CDropDown::ManuallyHandleKeys(const SDL_Event_* ev) break; default: - // If we have inputed a character try to get the closest element to it. + // If we have typed a character try to get the closest element to it. // TODO: not too nice and doesn't deal with dashes. if (m_Open && ((szChar >= SDLK_a && szChar <= SDLK_z) || szChar == SDLK_SPACE || (szChar >= SDLK_0 && szChar <= SDLK_9) - || (szChar >= SDLK_KP_0 && szChar <= SDLK_KP_9))) + || (szChar >= SDLK_KP_1 && szChar <= SDLK_KP_0))) { // arbitrary 1 second limit to add to string or start fresh. // maximal amount of characters is 100, which imo is far more than enough. diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 39b294c1c9..36ef4a6f92 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2019 Wildfire Games. +/* Copyright (c) 2020 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -80,6 +80,9 @@ inline void ignore_result(const T&) {} #if GCC_VERSION # define NOTHROW_DECLARE __attribute__((nothrow)) # define NOTHROW_DEFINE // not supported for definitions +#elif CLANG_VERSION +# define NOTHROW_DECLARE __attribute__((nothrow)) +# define NOTHROW_DEFINE // not supported for definitions #elif MSC_VERSION // Kevin Frei, 2006-03-23: "I work on the Visual C++ compiler team, // and agree completely with Paul Parks: don't use throw(), because diff --git a/source/lib/path.h b/source/lib/path.h index d2d7707396..3c638507ae 100644 --- a/source/lib/path.h +++ b/source/lib/path.h @@ -288,7 +288,7 @@ private: // annoying and inefficient. we allow either type of separators, // appending whichever was first encountered. when modifying the path, // we ensure the same separator is used. - wchar_t separator; + wchar_t separator = L'/'; }; static inline std::wostream& operator<<(std::wostream& s, const Path& path) diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index 09582038e9..52e18b461f 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -545,7 +545,7 @@ void XmppClient::GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::Mu ScriptInterface::CreateArray(rq, ret); int j = 0; - for (const std::pair& p : m_PlayerMap) + for (const std::pair& p : m_PlayerMap) { JS::RootedValue player(rq.cx); diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 124b390d0d..24467b3629 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -277,7 +277,7 @@ void CNetClient::PostPlayerAssignmentsToScript() JS::RootedValue newAssignments(rq.cx); ScriptInterface::CreateObject(rq, &newAssignments); - for (const std::pair& p : m_PlayerAssignments) + for (const std::pair& p : m_PlayerAssignments) { JS::RootedValue assignment(rq.cx); diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index b6c8babcb2..ed77b6e352 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -738,7 +738,7 @@ void CNetServerWorker::AddPlayer(const CStr& guid, const CStrW& name) { // Find all player IDs in active use; we mustn't give them to a second player (excluding the unassigned ID: -1) std::set usedIDs; - for (const std::pair& p : m_PlayerAssignments) + for (const std::pair& p : m_PlayerAssignments) if (p.second.m_Enabled && p.second.m_PlayerID != -1) usedIDs.insert(p.second.m_PlayerID); diff --git a/source/network/NetServerTurnManager.cpp b/source/network/NetServerTurnManager.cpp index 21108d5dd9..2c2f0f2ed2 100644 --- a/source/network/NetServerTurnManager.cpp +++ b/source/network/NetServerTurnManager.cpp @@ -72,7 +72,7 @@ void CNetServerTurnManager::NotifyFinishedClientCommands(CNetServerSession& sess void CNetServerTurnManager::CheckClientsReady() { // See if all clients (including self) are ready for a new turn - for (const std::pair& clientReady : m_ClientsReady) + for (const std::pair& clientReady : m_ClientsReady) { NETSERVERTURN_LOG(" %d: %d <=? %d\n", clientReady.first, clientReady.second, m_ReadyTurn); if (clientReady.second <= m_ReadyTurn) @@ -122,7 +122,7 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession& sessio // Find the newest turn which we know all clients have simulated u32 newest = std::numeric_limits::max(); - for (const std::pair& clientSimulated : m_ClientsSimulated) + for (const std::pair& clientSimulated : m_ClientsSimulated) if (clientSimulated.second < newest) newest = clientSimulated.second; @@ -137,7 +137,7 @@ void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession& sessio // Find all players that are OOS on that turn std::vector OOSPlayerNames; - for (const std::pair& hashPair : clientStateHash.second) + for (const std::pair& hashPair : clientStateHash.second) { NETSERVERTURN_LOG("sync check %d: %d = %hs\n", it->first, cit->first, Hexify(cit->second).c_str()); if (hashPair.second != expected) diff --git a/source/ps/ConfigDB.cpp b/source/ps/ConfigDB.cpp index 2da15c2c8a..a99f190504 100644 --- a/source/ps/ConfigDB.cpp +++ b/source/ps/ConfigDB.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -188,11 +188,11 @@ std::map CConfigDB::GetValuesWithPrefix(EConfigNamespace // Loop upwards so that values in later namespaces can override // values in earlier namespaces for (int search_ns = 0; search_ns <= ns; ++search_ns) - for (const std::pair& p : m_Map[search_ns]) + for (const std::pair& p : m_Map[search_ns]) if (boost::algorithm::starts_with(p.first, prefix)) ret[p.first] = p.second; - for (const std::pair& p : m_Map[CFG_COMMAND]) + for (const std::pair& p : m_Map[CFG_COMMAND]) if (boost::algorithm::starts_with(p.first, prefix)) ret[p.first] = p.second; @@ -431,7 +431,8 @@ bool CConfigDB::WriteFile(EConfigNamespace ns, const VfsPath& path) const shared_ptr buf; AllocateAligned(buf, 1*MiB, maxSectorSize); char* pos = (char*)buf.get(); - for (const std::pair& p : m_Map[ns]) + + for (const std::pair& p : m_Map[ns]) { size_t i; pos += sprintf(pos, "%s = ", p.first.c_str()); diff --git a/source/ps/Hotkey.cpp b/source/ps/Hotkey.cpp index 74f9bba6a9..287c250374 100644 --- a/source/ps/Hotkey.cpp +++ b/source/ps/Hotkey.cpp @@ -40,7 +40,7 @@ static_assert(SDL_USEREVENT_ == SDL_USEREVENT, "SDL_USEREVENT_ is not the same t // all key combinations that trigger it. static void LoadConfigBindings() { - for (const std::pair& configPair : g_ConfigDB.GetValuesWithPrefix(CFG_COMMAND, "hotkey.")) + for (const std::pair& configPair : g_ConfigDB.GetValuesWithPrefix(CFG_COMMAND, "hotkey.")) { std::string hotkeyName = configPair.first.substr(7); // strip the "hotkey." prefix for (const CStr& hotkey : configPair.second) @@ -93,7 +93,7 @@ void LoadHotkeys() // Set up the state of the hotkeys given no key is down. // i.e. find those hotkeys triggered by all negations. - for (const std::pair& p : g_HotkeyMap) + for (const std::pair& p : g_HotkeyMap) for (const SHotkeyMapping& hotkey : p.second) { if (!hotkey.negated) diff --git a/source/ps/ProfileViewer.cpp b/source/ps/ProfileViewer.cpp index d6c8052292..b6805da171 100644 --- a/source/ps/ProfileViewer.cpp +++ b/source/ps/ProfileViewer.cpp @@ -402,10 +402,11 @@ void CProfileViewer::AddRootTable(AbstractProfileTable* table, bool front) namespace { - struct WriteTable + class WriteTable { - std::ofstream& f; - WriteTable(std::ofstream& f) : f(f) {} + public: + WriteTable(std::ofstream& outputStream) : m_OutputStream(outputStream) {} + WriteTable(const WriteTable& writeTable) = default; void operator() (AbstractProfileTable* table) { @@ -435,7 +436,7 @@ namespace // Output data as a formatted table: - f << "\n\n" << table->GetTitle() << "\n"; + m_OutputStream << "\n\n" << table->GetTitle() << "\n"; if (cols == 0) // avoid divide-by-zero return; @@ -443,14 +444,14 @@ namespace for (size_t r = 0; r < data.size()/cols; ++r) { for (size_t c = 0; c < cols; ++c) - f << (c ? " | " : "\n") + m_OutputStream << (c ? " | " : "\n") << data[r*cols + c].Pad(PS_TRIM_RIGHT, columnWidths[c]); // Add dividers under some rows. (Currently only the first, since // that contains the column headers.) if (r == 0) for (size_t c = 0; c < cols; ++c) - f << (c ? "-|-" : "\n") + m_OutputStream << (c ? "-|-" : "\n") << CStr::Repeat("-", columnWidths[c]); } } @@ -480,6 +481,7 @@ namespace } private: + std::ofstream& m_OutputStream; const WriteTable& operator=(const WriteTable&); }; diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index e13b14b7f0..80ef17bd17 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -599,7 +599,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize) curTime += 0.000001; } // sub-events, aggregated - for (const std::pair& type : timeByType) + for (const std::pair& type : timeByType) { CProfiler2::SItem_dt_id item = { (float)curTime, std::get<0>(type.second) }; buffer[writePos] = (u8)CProfiler2::ITEM_ENTER; diff --git a/source/ps/XML/XeroXMB.h b/source/ps/XML/XeroXMB.h index 7ecee9b5b8..eae3d3ff0a 100644 --- a/source/ps/XML/XeroXMB.h +++ b/source/ps/XML/XeroXMB.h @@ -195,7 +195,7 @@ public: typedef std::forward_iterator_tag iterator_category; iterator(size_t size, const char* ptr, const char* endptr = NULL) - : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr), m_Pointer(ptr) {} + : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr) {} XMBElement operator*() const { return XMBElement(m_CurPointer); } XMBElement operator->() const { return **this; } iterator& operator++(); @@ -211,7 +211,6 @@ public: size_t m_Size; size_t m_CurItemID; const char* m_CurPointer; - const char* m_Pointer; }; iterator begin() { return iterator(m_Size, m_Pointer); } iterator end() { return iterator(m_Size, m_Pointer, m_EndPointer); } @@ -264,7 +263,7 @@ public: typedef std::forward_iterator_tag iterator_category; iterator(size_t size, const char* ptr, const char* endptr = NULL) - : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr), m_Pointer(ptr) {} + : m_Size(size), m_CurItemID(endptr ? size : 0), m_CurPointer(endptr ? endptr : ptr) {} XMBAttribute operator*() const; XMBAttribute operator->() const { return **this; } iterator& operator++(); @@ -280,7 +279,6 @@ public: size_t m_Size; size_t m_CurItemID; const char* m_CurPointer; - const char* m_Pointer; }; iterator begin() const { return iterator(m_Size, m_Pointer); } iterator end() const { return iterator(m_Size, m_Pointer, m_EndPointer); } diff --git a/source/ps/scripting/JSInterface_Hotkey.cpp b/source/ps/scripting/JSInterface_Hotkey.cpp index 9486f4721f..15406d537a 100644 --- a/source/ps/scripting/JSInterface_Hotkey.cpp +++ b/source/ps/scripting/JSInterface_Hotkey.cpp @@ -75,7 +75,7 @@ JS::Value GetHotkeyMap(ScriptInterface::CmptPrivate* pCmptPrivate) JS::RootedValue hotkeyMap(rq.cx); std::unordered_map>> hotkeys; - for (const std::pair& key : g_HotkeyMap) + for (const std::pair& key : g_HotkeyMap) for (const SHotkeyMapping& mapping : key.second) { std::vector keymap; diff --git a/source/ps/scripting/JSInterface_ModIo.cpp b/source/ps/scripting/JSInterface_ModIo.cpp index 9e472079a3..7387f8b01b 100644 --- a/source/ps/scripting/JSInterface_ModIo.cpp +++ b/source/ps/scripting/JSInterface_ModIo.cpp @@ -99,7 +99,7 @@ JS::Value JSI_ModIo::GetMods(ScriptInterface::CmptPrivate* pCmptPrivate) JS::RootedValue m(rq.cx); ScriptInterface::CreateObject(rq, &m); - for (const std::pair& prop : mod.properties) + for (const std::pair& prop : mod.properties) scriptInterface->SetProperty(m, prop.first.c_str(), prop.second, true); scriptInterface->SetProperty(m, "dependencies", mod.dependencies, true);