Skip to content

Commit

Permalink
✅ add test to compile without exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Aug 10, 2020
1 parent 1b28a58 commit 4080d0b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
Expand Down
6 changes: 4 additions & 2 deletions include/nlohmann/ordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <utility> // pair
#include <vector> // vector

#include <nlohmann/detail/macro_scope.hpp>

namespace nlohmann
{

Expand Down Expand Up @@ -64,7 +66,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
}
}

throw std::out_of_range("key not found");
JSON_THROW(std::out_of_range("key not found"));
}

const T& at(const Key& key) const
Expand All @@ -77,7 +79,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
}
}

throw std::out_of_range("key not found");
JSON_THROW(std::out_of_range("key not found"));
}

size_type erase(const Key& key)
Expand Down
7 changes: 5 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16395,6 +16395,9 @@ class serializer
#include <utility> // pair
#include <vector> // vector

// #include <nlohmann/detail/macro_scope.hpp>


namespace nlohmann
{

Expand Down Expand Up @@ -16454,7 +16457,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
}
}

throw std::out_of_range("key not found");
JSON_THROW(std::out_of_range("key not found"));
}

const T& at(const Key& key) const
Expand All @@ -16467,7 +16470,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
}
}

throw std::out_of_range("key not found");
JSON_THROW(std::out_of_range("key not found"));
}

size_type erase(const Key& key)
Expand Down
7 changes: 7 additions & 0 deletions test/cmake_add_subdirectory/project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ target_link_libraries(with_namespace_target nlohmann_json::nlohmann_json)

add_executable(without_namespace_target main.cpp)
target_link_libraries(without_namespace_target nlohmann_json)

if(NOT MSVC)
add_executable(without_exceptions main.cpp)
target_link_libraries(without_exceptions nlohmann_json::nlohmann_json)
target_compile_definitions(without_exceptions PRIVATE JSON_NOEXCEPTION)
target_compile_options(without_exceptions PRIVATE -fno-exceptions)
endif()

0 comments on commit 4080d0b

Please sign in to comment.