diff --git a/Makefile b/Makefile index fe207dd33..e32a231bc 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ ifdef CLANG_WARNINGS -Wno-inconsistent-missing-destructor-override -Wno-float-equal \ -Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables \ -Wno-four-char-constants -Wno-padded -Wno-reserved-identifier \ - -Wno-duplicate-enum + -Wno-duplicate-enum -Wno-unsafe-buffer-usage CXXFLAGS+= $(EXTRA_WARN) CFLAGS+= $(EXTRA_WARN) diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index 8ad996f7c..5808e4275 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -90,7 +90,7 @@ class KeyMap nlohmann::json saveMapping(const EventMode mode) const; int loadMapping(const nlohmann::json& mapping, const EventMode mode); - static nlohmann::json convertLegacyMapping(string_view list); + static nlohmann::json convertLegacyMapping(string_view lm); /** Erase all mappings for given mode */ void eraseMode(const EventMode mode); diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 22d23ebd0..89148edec 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -47,7 +47,7 @@ PhysicalJoystickHandler::PhysicalJoystickHandler( } json mappings; - string_view serializedMapping = myOSystem.settings().getString("joymap"); + const string_view serializedMapping = myOSystem.settings().getString("joymap"); try { mappings = json::parse(serializedMapping); diff --git a/src/common/TimerManager.cxx b/src/common/TimerManager.cxx index 1f058f22f..35d80eacd 100644 --- a/src/common/TimerManager.cxx +++ b/src/common/TimerManager.cxx @@ -106,7 +106,7 @@ std::size_t TimerManager::size() const noexcept bool TimerManager::empty() const noexcept { const ScopedLock lock(sync); - return active.empty(); + return active.empty(); // NOLINT: bugprone-standalone-empty } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -241,7 +241,7 @@ TimerManager::Timer::Timer(Timer&& r) noexcept // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TimerManager::Timer::Timer(TimerId tid, Timestamp tnext, Duration tperiod, const TFunction& func) noexcept - : id{tid }, + : id{tid}, next{tnext}, period{tperiod}, handler{func} diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index fd26b6b07..4e70e9837 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -131,7 +131,7 @@ uInt64 ZipHandler::decompress(ByteBuffer& image) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string ZipHandler::errorMessage(ZipError err) { - static constexpr std::array zip_error_s = { + static constexpr std::array zip_error_s = { "ZIP NONE", "ZIP OUT_OF_MEMORY", "ZIP FILE_ERROR", @@ -143,7 +143,7 @@ string ZipHandler::errorMessage(ZipError err) "ZIP LZMA_UNSUPPORTED", "ZIP BUFFER_TOO_SMALL" }; - return zip_error_s[static_cast(err)]; + return string{zip_error_s[static_cast(err)]}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/CartBUSWidget.cxx b/src/debugger/gui/CartBUSWidget.cxx index 38095001c..55931a30b 100644 --- a/src/debugger/gui/CartBUSWidget.cxx +++ b/src/debugger/gui/CartBUSWidget.cxx @@ -453,7 +453,7 @@ string CartridgeBUSWidget::bankState() if (myCart.myBUSSubtype == CartridgeBUS::BUSSubtype::BUS0) { - static constexpr std::array spot = { + static constexpr std::array spot = { "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; buf << "Bank = " << std::dec << myCart.getBank() @@ -461,7 +461,7 @@ string CartridgeBUSWidget::bankState() } else { - static constexpr std::array spot = { + static constexpr std::array spot = { "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; buf << "Bank = " << std::dec << myCart.getBank() diff --git a/src/debugger/gui/CartCDFWidget.cxx b/src/debugger/gui/CartCDFWidget.cxx index 3f93ac4b4..ccc27108b 100644 --- a/src/debugger/gui/CartCDFWidget.cxx +++ b/src/debugger/gui/CartCDFWidget.cxx @@ -439,7 +439,7 @@ string CartridgeCDFWidget::bankState() { ostringstream& buf = buffer(); - static constexpr std::array spot = { + static constexpr std::array spot = { "$FFF4", "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; diff --git a/src/debugger/gui/CartCTYWidget.cxx b/src/debugger/gui/CartCTYWidget.cxx index 3449ce677..f506714ea 100644 --- a/src/debugger/gui/CartCTYWidget.cxx +++ b/src/debugger/gui/CartCTYWidget.cxx @@ -93,7 +93,7 @@ string CartridgeCTYWidget::bankState() { ostringstream& buf = buffer(); - static constexpr std::array spot = { + static constexpr std::array spot = { "", "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; const uInt16 bank = myCart.getBank(); diff --git a/src/debugger/gui/CartDPCPlusWidget.cxx b/src/debugger/gui/CartDPCPlusWidget.cxx index 889cfe93b..1a925b7f7 100644 --- a/src/debugger/gui/CartDPCPlusWidget.cxx +++ b/src/debugger/gui/CartDPCPlusWidget.cxx @@ -338,7 +338,7 @@ string CartridgeDPCPlusWidget::bankState() { ostringstream& buf = buffer(); - static constexpr std::array spot = { + static constexpr std::array spot = { "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; buf << "Bank = " << std::dec << myCart.getBank() diff --git a/src/debugger/gui/CartE7Widget.cxx b/src/debugger/gui/CartE7Widget.cxx index b1741f9d6..4f1145a16 100644 --- a/src/debugger/gui/CartE7Widget.cxx +++ b/src/debugger/gui/CartE7Widget.cxx @@ -70,7 +70,7 @@ void CartridgeE7Widget::initialize(GuiObject* boss, VariantList items0, items1; for(int i = 0; i < cart.romBankCount(); ++i) - VarList::push_back(items0, getSpotLower(i)); + VarList::push_back(items0, getSpotLower(i, myCart.romBankCount())); for(int i = 0; i < 4; ++i) VarList::push_back(items1, getSpotUpper(i)); @@ -139,7 +139,7 @@ string CartridgeE7Widget::bankState() ostringstream& buf = buffer(); buf << "Segments: " << std::dec - << getSpotLower(myCart.myCurrentBank[0]) << " / " + << getSpotLower(myCart.myCurrentBank[0], myCart.romBankCount()) << " / " << getSpotUpper(myCart.myCurrentRAM); return buf.str(); @@ -202,7 +202,7 @@ uInt8 CartridgeE7Widget::internalRamGetValue(int addr) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string_view CartridgeE7Widget::getSpotLower(int idx) const +string_view CartridgeE7Widget::getSpotLower(int idx, int bankcount) { static constexpr std::array spot_lower_8K = { "#0 - ROM ($FFE4)", "#1 - ROM ($FFE5)", "#2 - ROM ($FFE6)", "#3 - RAM ($FFE7)" @@ -216,16 +216,16 @@ string_view CartridgeE7Widget::getSpotLower(int idx) const "#4 - ROM ($FFE4)", "#5 - ROM ($FFE5)", "#6 - ROM ($FFE6)", "#7 - RAM ($FFE7)" }; - return myCart.romBankCount() == 4 + return bankcount == 4 ? spot_lower_8K[idx] - : myCart.romBankCount() == 6 + : bankcount == 6 ? spot_lower_12K[idx] : spot_lower_16K[idx]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string_view CartridgeE7Widget::getSpotUpper(int idx) const +string_view CartridgeE7Widget::getSpotUpper(int idx) { static constexpr std::array spot_upper = { "#0 - RAM ($FFE8)", "#1 - RAM ($FFE9)", "#2 - RAM ($FFEA)", "#3 - RAM ($FFEB)" diff --git a/src/debugger/gui/CartE7Widget.hxx b/src/debugger/gui/CartE7Widget.hxx index 6c124a38e..9f8f3c15a 100644 --- a/src/debugger/gui/CartE7Widget.hxx +++ b/src/debugger/gui/CartE7Widget.hxx @@ -54,8 +54,6 @@ class CartridgeE7Widget : public CartDebugWidget protected: void initialize(GuiObject* boss, const CartridgeE7& cart, const ostringstream& info); - string_view getSpotLower(int idx) const; - string_view getSpotUpper(int idx) const; private: void saveOldState() override; @@ -72,6 +70,9 @@ class CartridgeE7Widget : public CartDebugWidget uInt8 internalRamGetValue(int addr) override; // end of functions for Cartridge RAM tab + static string_view getSpotLower(int idx, int bankcount); + static string_view getSpotUpper(int idx); + private: // Following constructors and assignment operators not supported CartridgeE7Widget() = delete; diff --git a/src/debugger/gui/RiotWidget.cxx b/src/debugger/gui/RiotWidget.cxx index 3970609bb..a7f7a0ac1 100644 --- a/src/debugger/gui/RiotWidget.cxx +++ b/src/debugger/gui/RiotWidget.cxx @@ -125,14 +125,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, CREATE_IO_REGS("SWCHB(R)", mySWCHBReadBits, kSWCHBRBitsID, true) // Timer registers (R/W) - static constexpr std::array writeNames = { + static constexpr std::array writeNames = { "TIM1T", "TIM8T", "TIM64T", "T1024T" }; ypos += _lineHeight + vGap * 4; for(int row = 0; row < 4; ++row) { - myTimWriteLabel[row] = new StaticTextWidget(boss, lfont, hBorder, ypos + row * _lineHeight + 2, - writeNames[row]); + myTimWriteLabel[row] = new StaticTextWidget(boss, lfont, hBorder, + ypos + row * _lineHeight + 2, writeNames[row]); } xpos = hBorder + lwidth; myTimWrite = new DataGridWidget(boss, nfont, xpos, ypos, 1, 4, 2, 8, Common::Base::Fmt::_16); @@ -150,14 +150,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, myTimAvail->setEditable(false); // Timer registers (RO) - static constexpr std::array readNames = { + static constexpr std::array readNames = { "INTIM", " Clocks", "TIMINT" }; ypos = myTimWrite->getBottom() + _lineHeight / 2; for(int row = 0; row < 3; ++row) { - t = new StaticTextWidget(boss, lfont, hBorder, ypos + row * _lineHeight + 2, - readNames[row]); + new StaticTextWidget(boss, lfont, hBorder, ypos + row * _lineHeight + 2, + readNames[row]); } xpos = hBorder + lwidth; myTimRead = new DataGridWidget(boss, nfont, xpos, ypos, 1, 3, 2, 30, Common::Base::Fmt::_16); @@ -181,7 +181,7 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, // Controller ports - int col = mySWCHAWriteBits->getRight() + hGap * 2.5; + const int col = mySWCHAWriteBits->getRight() + hGap * 2.5; xpos = col; ypos = vBorder; myLeftControl = addControlWidget(boss, lfont, xpos, ypos, instance().console().leftController()); @@ -192,14 +192,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, addToFocusList(myRightControl->getFocusList()); // TIA INPTx registers (R), left port - static constexpr std::array contLeftReadNames = { + static constexpr std::array contLeftReadNames = { "INPT0", "INPT1", "INPT4" }; xpos = myLeftControl->getLeft(); ypos += myLeftControl->getHeight() + 2 * _lineHeight; for(int row = 0; row < 3; ++row) { t = new StaticTextWidget(boss, lfont, xpos, ypos + row * _lineHeight + 2, - contLeftReadNames[row]); + contLeftReadNames[row]); } xpos = t->getRight() + hGap; myLeftINPT = new DataGridWidget(boss, nfont, xpos, ypos, 1, 3, 2, 8, Common::Base::Fmt::_16); @@ -207,14 +207,14 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, myLeftINPT->setEditable(false); // TIA INPTx registers (R), right port - static constexpr std::array contRightReadNames = { + static constexpr std::array contRightReadNames = { "INPT2", "INPT3", "INPT5" }; xpos = myRightControl->getLeft(); for(int row = 0; row < 3; ++row) { t = new StaticTextWidget(boss, lfont, xpos, ypos + row*_lineHeight + 2, - contRightReadNames[row]); + contRightReadNames[row]); } xpos = t->getRight() + hGap; myRightINPT = new DataGridWidget(boss, nfont, xpos, ypos, 1, 3, 2, 8, Common::Base::Fmt::_16); diff --git a/src/debugger/gui/TiaWidget.cxx b/src/debugger/gui/TiaWidget.cxx index e55e78a6d..3bc6ce0e2 100644 --- a/src/debugger/gui/TiaWidget.cxx +++ b/src/debugger/gui/TiaWidget.cxx @@ -48,7 +48,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, vGap = fontHeight / 2, hBorder = 10, vBorder = 10; - int xpos = hBorder, ypos = vBorder, buttonX, buttonY; + int xpos = hBorder, ypos = vBorder; StaticTextWidget* t = nullptr; ButtonWidget* b = nullptr; @@ -56,7 +56,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, //////////////////////////// // VSync/VBlank //////////////////////////// - buttonX = xpos; buttonY = ypos; + int buttonX = xpos, buttonY = ypos; myVSync = new CheckboxWidget(boss, lfont, buttonX, buttonY, "VSync", kVSyncCmd); myVSync->setTarget(this); addFocusWidget(myVSync); @@ -68,7 +68,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, // Color registers ypos = vBorder + lineHeight * 2 + vGap / 2; - static constexpr std::array regNames = { + static constexpr std::array regNames = { "COLUP0", "COLUP1", "COLUPF", "COLUBK" }; for(int row = 0; row < 4; ++row) @@ -108,7 +108,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, myFixedEnabled->setTarget(this); addFocusWidget(myFixedEnabled); - static constexpr std::array dbgLabels = { + static constexpr std::array dbgLabels = { "P0", "P1", "PF", "BK", "M0", "M1", "BL", "HM" }; for(uInt32 row = 0; row <= 3; ++row) @@ -136,8 +136,8 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, xpos = myFixedColors[4]->getRight() + 6 * hGap; ypos = vBorder + lineHeight; // Add all 15 collision bits (with labels) - static constexpr std::array rowLabel = { "P0", "P1", "M0", "M1", "BL" }; - static constexpr std::array colLabel = { "PF", "BL", "M1", "M0", "P1" }; + static constexpr std::array rowLabel = { "P0", "P1", "M0", "M1", "BL" }; + static constexpr std::array colLabel = { "PF", "BL", "M1", "M0", "P1" }; int idx = 0; for(uInt32 row = 0; row < 5; ++row) { @@ -154,7 +154,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, if(row == 0) { // Add centered horizontal label - int labelx = collX - (2 * fontWidth - myCollision[idx]->getWidth()) / 2; + const int labelx = collX - (2 * fontWidth - myCollision[idx]->getWidth()) / 2; new StaticTextWidget(boss, lfont, labelx, ypos - lineHeight, colLabel[col]); } collX += fontWidth * 2 + hGap; @@ -473,7 +473,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& sf = instance().frameBuffer().smallFont(); const int sfWidth = sf.getMaxCharWidth(), sfHeight = sf.getFontHeight(); - static constexpr std::array bitNames = { + static constexpr std::array bitNames = { "0", "1", "2", "3", "4", "5", "6", "7" }; diff --git a/src/debugger/yacc/YaccParser.cxx b/src/debugger/yacc/YaccParser.cxx index 2c1a11d21..f4cd2bb33 100644 --- a/src/debugger/yacc/YaccParser.cxx +++ b/src/debugger/yacc/YaccParser.cxx @@ -25,8 +25,21 @@ namespace YaccParser { #include #include "y.tab.h" -static YYSTYPE result; -static string errMsg; + +enum class State { + DEFAULT, + IDENTIFIER, + OPERATOR, + SPACE +}; + +namespace { + YYSTYPE result; + string errMsg; + + State state = State::DEFAULT; + const char *input, *c; +} // namespace void yyerror(const char* e); @@ -41,15 +54,6 @@ void yyerror(const char* e); #include "y.tab.c" #endif -enum class State { - DEFAULT, - IDENTIFIER, - OPERATOR, - SPACE -}; - -static State state = State::DEFAULT; -static const char *input, *c; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& errorMessage() diff --git a/src/emucore/CartBUS.cxx b/src/emucore/CartBUS.cxx index dc6a77801..13b8a6ecd 100644 --- a/src/emucore/CartBUS.cxx +++ b/src/emucore/CartBUS.cxx @@ -28,21 +28,22 @@ #include "CartBUS.hxx" #include "exception/FatalEmulationError.hxx" -// Location of data within the RAM copy of the BUS Driver. -static constexpr int +namespace { + // Location of data within the RAM copy of the BUS Driver. + constexpr int COMMSTREAM = 0x10, JUMPSTREAM = 0x11; -static constexpr bool BUS_STUFF_ON(uInt8 mode) { return (mode & 0x0F) == 0; } -static constexpr bool DIGITAL_AUDIO_ON(uInt8 mode) { return (mode & 0xF0) == 0; } - -static constexpr uInt32 getUInt32(const uInt8* _array, size_t _address) { - return static_cast((_array)[(_address) + 0] + - ((_array)[(_address) + 1] << 8) + - ((_array)[(_address) + 2] << 16) + - ((_array)[(_address) + 3] << 24)); -} + constexpr bool BUS_STUFF_ON(uInt8 mode) { return (mode & 0x0F) == 0; } + constexpr bool DIGITAL_AUDIO_ON(uInt8 mode) { return (mode & 0xF0) == 0; } + constexpr uInt32 getUInt32(const uInt8* _array, size_t _address) { + return static_cast((_array)[(_address) + 0] + + ((_array)[(_address) + 1] << 8) + + ((_array)[(_address) + 2] << 16) + + ((_array)[(_address) + 3] << 24)); + } +} // namespace // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeBUS::CartridgeBUS(const ByteBuffer& image, size_t size, diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index f20b91651..82698b4e5 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -28,17 +28,17 @@ #include "TIA.hxx" #include "exception/FatalEmulationError.hxx" -static constexpr bool FAST_FETCH_ON(uInt8 mode) { return (mode & 0x0F) == 0; } -static constexpr bool DIGITAL_AUDIO_ON(uInt8 mode) { return (mode & 0xF0) == 0; } - -static constexpr uInt32 getUInt32(const uInt8* _array, size_t _address) { - return static_cast((_array)[(_address) + 0] + - ((_array)[(_address) + 1] << 8) + - ((_array)[(_address) + 2] << 16) + - ((_array)[(_address) + 3] << 24)); -} - namespace { + constexpr bool FAST_FETCH_ON(uInt8 mode) { return (mode & 0x0F) == 0; } + constexpr bool DIGITAL_AUDIO_ON(uInt8 mode) { return (mode & 0xF0) == 0; } + + constexpr uInt32 getUInt32(const uInt8* _array, size_t _address) { + return static_cast((_array)[(_address) + 0] + + ((_array)[(_address) + 1] << 8) + + ((_array)[(_address) + 2] << 16) + + ((_array)[(_address) + 3] << 24)); + } + Thumbulator::ConfigureFor thumulatorConfiguration(CartridgeCDF::CDFSubtype subtype) { switch (subtype) { diff --git a/src/emucore/CartMVC.cxx b/src/emucore/CartMVC.cxx index 6480d49fe..5258f5153 100755 --- a/src/emucore/CartMVC.cxx +++ b/src/emucore/CartMVC.cxx @@ -378,7 +378,7 @@ static constexpr uInt8 scale9[16] = { static constexpr uInt8 scale10[16] = { 0, 0, 0, 0, 0, 1, 3, 6, 9, 12, 14, 15, 15, 15, 15, 15 /* 2.7778 */ }; -static const uInt8* scales[11] = { +static constexpr const uInt8* const scales[11] = { scale0, scale1, scale2, scale3, scale4, scale5, scale6, scale7, scale8, scale9, scale10 }; diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 777c5e81e..261680b6b 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -105,7 +105,8 @@ bool Controller::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Controller::getName(const Type type) { - static constexpr std::array(Controller::Type::LastType)> NAMES = + static constexpr std::array(Controller::Type::LastType)> NAMES = { "Unknown", "Amiga mouse", "Atari mouse", "AtariVox", "Booster Grip", "CompuMate", @@ -114,13 +115,13 @@ string Controller::getName(const Type type) "Light Gun", "QuadTari", "Joy 2B+" }; - return NAMES[static_cast(type)]; + return string{NAMES[static_cast(type)]}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Controller::getPropName(const Type type) { - static constexpr std::array(Controller::Type::LastType)> PROP_NAMES = { "AUTO", @@ -130,7 +131,7 @@ string Controller::getPropName(const Type type) "LIGHTGUN", "QUADTARI", "JOY_2B+" }; - return PROP_NAMES[static_cast(type)]; + return string{PROP_NAMES[static_cast(type)]}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Serializer.cxx b/src/emucore/Serializer.cxx index 8ea828f9b..2cdb3c625 100644 --- a/src/emucore/Serializer.cxx +++ b/src/emucore/Serializer.cxx @@ -49,7 +49,7 @@ Serializer::Serializer(string_view filename, Mode m) // So we open in write and append mode - the write creates the file // when necessary, and the append doesn't delete any data if it // already exists - string f{filename}; + const string f{filename}; fstream temp(f, ios::out | ios::app); temp.close();