From 357e51c09aeee1f7f178f0f9e8dc5803e5e0c73f Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 18 Oct 2021 17:19:28 +0100 Subject: [PATCH] Clarify some (no) exception specifications. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/TestRunner.cpp | 4 ++-- M6502/HarteTest_6502/cycle_t.cpp | 19 +++++++------------ M6502/HarteTest_6502/cycle_t.h | 11 +++++------ M6502/HarteTest_6502/cycles_t.h | 4 ++-- M6502/HarteTest_6502/ram_t.h | 10 +++++----- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index 2499c7f..e961781 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -149,8 +149,8 @@ bool TestRunner::checkState() { return false; for (int i = 0; i < expected_cycles.size(); ++i) { - const auto& expected = expected_cycles.at(i); - const auto& actual = actual_cycles.at(i); // actual could be less than expected + const auto& expected = expected_cycles[i]; + const auto& actual = actual_cycles[i]; // actual could be less than expected check("Cycle address", expected.address(), actual.address()); check("Cycle value", expected.value(), actual.value()); check("Cycle action", expected.action(), actual.action()); diff --git a/M6502/HarteTest_6502/cycle_t.cpp b/M6502/HarteTest_6502/cycle_t.cpp index de83855..1ecdbf8 100644 --- a/M6502/HarteTest_6502/cycle_t.cpp +++ b/M6502/HarteTest_6502/cycle_t.cpp @@ -4,38 +4,33 @@ #include #include -cycle_t::action_t cycle_t::to_action(std::string value) { +cycle_t::action_t cycle_t::to_action(std::string value) noexcept { if (value == "read") return action_t::read; if (value == "write") return action_t::write; - throw new std::out_of_range("Unknown action"); + return action_t::unknown; } -std::string cycle_t::to_string(action_t value) { +std::string cycle_t::to_string(action_t value) noexcept { if (value == action_t::read) return "read"; if (value == action_t::write) return "write"; - throw new std::out_of_range("Unknown action"); + return "unknown"; } -cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) +cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept : m_address(address), m_value(value), m_action(action) {} -cycle_t::cycle_t(uint16_t address, uint8_t value, std::string action) -: m_address(address), - m_value(value), - m_action(to_action(action)) {} - #ifdef USE_SIMDJSON_JSON -cycle_t::cycle_t(simdjson::dom::element input) +cycle_t::cycle_t(simdjson::dom::element input) noexcept : cycle_t(input.get_array()) {} -cycle_t::cycle_t(simdjson::dom::array input) +cycle_t::cycle_t(simdjson::dom::array input) noexcept : m_address((uint16_t)(uint64_t)input.at(0)), m_value((uint8_t)(uint64_t)input.at(1)), m_action(to_action((std::string)input.at(2))) { diff --git a/M6502/HarteTest_6502/cycle_t.h b/M6502/HarteTest_6502/cycle_t.h index 7fe9f9f..1641726 100644 --- a/M6502/HarteTest_6502/cycle_t.h +++ b/M6502/HarteTest_6502/cycle_t.h @@ -29,15 +29,14 @@ private: action_t m_action = action_t::unknown; public: - [[nodiscard]] static action_t to_action(std::string value); - [[nodiscard]] static std::string to_string(action_t value); + [[nodiscard]] static std::string to_string(action_t value) noexcept; + [[nodiscard]] static action_t to_action(std::string value) noexcept; - cycle_t(uint16_t address, uint8_t value, action_t action); - cycle_t(uint16_t address, uint8_t value, std::string action); + cycle_t(uint16_t address, uint8_t value, action_t action) noexcept; #ifdef USE_SIMDJSON_JSON - cycle_t(simdjson::dom::element input); - cycle_t(simdjson::dom::array input); + cycle_t(simdjson::dom::element input) noexcept; + cycle_t(simdjson::dom::array input) noexcept; #endif #ifdef USE_BOOST_JSON diff --git a/M6502/HarteTest_6502/cycles_t.h b/M6502/HarteTest_6502/cycles_t.h index ca3bd54..f00ece6 100644 --- a/M6502/HarteTest_6502/cycles_t.h +++ b/M6502/HarteTest_6502/cycles_t.h @@ -53,6 +53,6 @@ public: void clear() { m_cycles.clear(); } - [[nodiscard]] auto& at(size_t idx) { return m_cycles.at(idx); } - [[nodiscard]] const auto& at(size_t idx) const { return m_cycles.at(idx); } + [[nodiscard]] auto& operator[](size_t idx) noexcept { return m_cycles[idx]; } + [[nodiscard]] const auto& operator[](size_t idx) const noexcept { return m_cycles[idx]; } }; diff --git a/M6502/HarteTest_6502/ram_t.h b/M6502/HarteTest_6502/ram_t.h index 40a4195..8ca5dda 100644 --- a/M6502/HarteTest_6502/ram_t.h +++ b/M6502/HarteTest_6502/ram_t.h @@ -42,13 +42,13 @@ public: ram_t(const Json::Value& input); #endif - [[nodiscard]] auto begin() const { return m_bytes.begin(); } - [[nodiscard]] auto end() const { return m_bytes.end(); } + [[nodiscard]] auto begin() const noexcept { return m_bytes.begin(); } + [[nodiscard]] auto end() const noexcept { return m_bytes.end(); } [[nodiscard]] auto size() const noexcept { return m_bytes.size(); } - void clear() { m_bytes.clear(); } + void clear() noexcept { m_bytes.clear(); } - [[nodiscard]] auto& at(size_t idx) { return m_bytes.at(idx); } - [[nodiscard]] const auto& at(size_t idx) const { return m_bytes.at(idx); } + [[nodiscard]] auto& operator[](size_t idx) noexcept { return m_bytes[idx]; } + [[nodiscard]] const auto& operator[](size_t idx) const noexcept { return m_bytes[idx]; } };