From 4080d0b1a4d551934676850e47cc38bad217826d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 10 Aug 2020 09:48:11 +0200 Subject: [PATCH] :white_check_mark: add test to compile without exceptions --- .github/workflows/ubuntu.yml | 1 - include/nlohmann/ordered_map.hpp | 6 ++++-- single_include/nlohmann/json.hpp | 7 +++++-- test/cmake_add_subdirectory/project/CMakeLists.txt | 7 +++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 2eefc1c35..1a47a885c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -4,7 +4,6 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest steps: diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 576790915..7dd644543 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -5,6 +5,8 @@ #include // pair #include // vector +#include + namespace nlohmann { @@ -64,7 +66,7 @@ template , } } - throw std::out_of_range("key not found"); + JSON_THROW(std::out_of_range("key not found")); } const T& at(const Key& key) const @@ -77,7 +79,7 @@ template , } } - throw std::out_of_range("key not found"); + JSON_THROW(std::out_of_range("key not found")); } size_type erase(const Key& key) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b8c6d516e..bfa5ed63d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16395,6 +16395,9 @@ class serializer #include // pair #include // vector +// #include + + namespace nlohmann { @@ -16454,7 +16457,7 @@ template , } } - throw std::out_of_range("key not found"); + JSON_THROW(std::out_of_range("key not found")); } const T& at(const Key& key) const @@ -16467,7 +16470,7 @@ template , } } - throw std::out_of_range("key not found"); + JSON_THROW(std::out_of_range("key not found")); } size_type erase(const Key& key) diff --git a/test/cmake_add_subdirectory/project/CMakeLists.txt b/test/cmake_add_subdirectory/project/CMakeLists.txt index 21357b685..caab6c4e1 100644 --- a/test/cmake_add_subdirectory/project/CMakeLists.txt +++ b/test/cmake_add_subdirectory/project/CMakeLists.txt @@ -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()