Skip to content

Commit e51a513

Browse files
committed
Avoid possible throw in noexcept function
1 parent bfc63ca commit e51a513

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

include/json2cpp/json2cpp.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ template<typename CharType> struct basic_json
199199
: parent_value_(&value), index_{ index }
200200
{}
201201

202-
constexpr const basic_json &operator*() const noexcept
202+
constexpr const basic_json &operator*() const
203203
{
204204
if (parent_value_->is_array()) {
205205
return (*parent_value_)[index_];
@@ -340,7 +340,7 @@ template<typename CharType> struct basic_json
340340
}
341341
}
342342

343-
template<typename Key>[[nodiscard]] constexpr std::size_t count(const Key &key) const noexcept
343+
template<typename Key>[[nodiscard]] constexpr std::size_t count(const Key &key) const
344344
{
345345
if (is_object()) {
346346
const auto found = find(key);
@@ -353,7 +353,7 @@ template<typename CharType> struct basic_json
353353
return 0;
354354
}
355355

356-
[[nodiscard]] constexpr iterator find(const std::basic_string_view<CharType> key) const noexcept
356+
[[nodiscard]] constexpr iterator find(const std::basic_string_view<CharType> key) const
357357
{
358358
for (auto itr = begin(); itr != end(); ++itr) {
359359
if (itr.key() == key) { return itr; }
@@ -392,7 +392,8 @@ template<typename CharType> struct basic_json
392392
{
393393
// I don't like this level of implicit conversions in the `get()` function,
394394
// but it's necessary for API compatibility with nlohmann::json
395-
if constexpr (std::is_same_v<Type, std::uint64_t> || std::is_same_v<Type, std::int64_t> || std::is_same_v<Type, double>) {
395+
if constexpr (std::is_same_v<Type,
396+
std::uint64_t> || std::is_same_v<Type, std::int64_t> || std::is_same_v<Type, double>) {
396397
if (const auto *uint_value = data.get_if_uinteger(); uint_value != nullptr) {
397398
return Type(*uint_value);
398399
} else if (const auto *value = data.get_if_integer(); value != nullptr) {
@@ -404,19 +405,20 @@ template<typename CharType> struct basic_json
404405
}
405406
} else if constexpr (std::is_same_v<Type,
406407
std::basic_string_view<CharType>> || std::is_same_v<Type, std::basic_string<CharType>>) {
407-
if (const auto *value = data.get_if_string(); value != nullptr) { return *value; }
408-
else {
408+
if (const auto *value = data.get_if_string(); value != nullptr) {
409+
return *value;
410+
} else {
409411
throw std::runtime_error("Unexpected type: string-like requested");
410412
}
411413
} else if constexpr (std::is_same_v<Type, bool>) {
412-
if (const auto *value = data.get_if_boolean(); value != nullptr) { return *value; }
413-
else {
414+
if (const auto *value = data.get_if_boolean(); value != nullptr) {
415+
return *value;
416+
} else {
414417
throw std::runtime_error("Unexpected type: bool requested");
415418
}
416419
} else {
417420
throw std::runtime_error("Unexpected type for get()");
418421
}
419-
420422
}
421423

422424
[[nodiscard]] constexpr bool is_object() const noexcept { return data.selected == data_t::selected_type::object; }

0 commit comments

Comments
 (0)