Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++17 copies of the test binaries #3101

Merged
merged 40 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
879217d
:alembic: add C++17 copies of the test binaries
nlohmann Oct 20, 2021
cf2a896
:alembic: add C++17 copies of the test binaries
nlohmann Oct 20, 2021
7fb709c
:alembic: add C++17 copies of the test binaries
nlohmann Oct 20, 2021
d90b6bc
:alembic: use proper header for filesystem
nlohmann Oct 20, 2021
03a75d5
:rotating_light: fix warnings
nlohmann Oct 20, 2021
c33bac8
:rewind: revert removal of code
nlohmann Oct 20, 2021
930e2cf
:alembic: use proper header for filesystem
nlohmann Oct 20, 2021
5cd67e7
:alembic: use proper header for filesystem
nlohmann Oct 20, 2021
12bb888
:alembic: do not use too old compilers with C++17
nlohmann Oct 20, 2021
2b431c2
:alembic: do not use too old compilers with C++17
nlohmann Oct 20, 2021
7543e17
:alembic: do not use too old compilers with C++17
nlohmann Oct 20, 2021
7e87863
:rotating_light: fix warning
nlohmann Oct 20, 2021
4c10cca
:hammer: cleanup
nlohmann Oct 20, 2021
ccd42cd
:rewind: undo cleanup
nlohmann Oct 20, 2021
d300856
:white_check_mark: add test
nlohmann Oct 21, 2021
37be287
:hammer: add more constraints #3097
nlohmann Oct 21, 2021
61829d7
:green_heart: remove leftover
nlohmann Oct 21, 2021
fed4114
:green_heart: replace "and" with "&&"
nlohmann Oct 21, 2021
cf6903e
Merge branch 'develop' of https://github.com/nlohmann/json into issue…
nlohmann Nov 21, 2021
19f75a2
:rotating_light: suppress modernize-concat-nested-namespaces warning
nlohmann Nov 21, 2021
7566b3b
Merge branch 'develop' of https://github.com/nlohmann/json into issue…
nlohmann Dec 23, 2021
62fe919
:alembic: use fix from https://github.com/nlohmann/json/pull/3101#iss…
nlohmann Dec 23, 2021
30ab9c4
:rotating_light: fix warnings
nlohmann Dec 24, 2021
1ca9510
:rotating_light: fix warnings
nlohmann Dec 24, 2021
742d85f
:rotating_light: fix warnings
nlohmann Dec 24, 2021
05874dc
:rotating_light: fix warnings
nlohmann Dec 24, 2021
69f9c41
:rotating_light: fix warnings
nlohmann Dec 24, 2021
78baaa9
:rotating_light: fix warnings
nlohmann Dec 24, 2021
4bf052a
:green_heart: fix script
nlohmann Dec 24, 2021
6e6a82f
:rotating_light: fix warnings
nlohmann Dec 24, 2021
7001266
:rotating_light: fix warnings
nlohmann Dec 24, 2021
8372e03
:rotating_light: fix warnings
nlohmann Dec 24, 2021
c4aecea
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
0c27b7c
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
5e12e56
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
d5a95e4
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
bd3270a
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
41a3b33
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
62c19f2
:alembic: use fix from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=9…
nlohmann Dec 28, 2021
eba77cd
:construction_worker: use published CI image
nlohmann Dec 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Checks: '*,
-llvmlibc-*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-readability-function-size,
-readability-function-cognitive-complexity,
Expand Down
2 changes: 1 addition & 1 deletion cmake/download_test_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ else()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE CXX_VERSION_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
string(REGEX REPLACE "[ ]*\n" "; " CXX_VERSION_RESULT "${CXX_VERSION_RESULT}")
message(STATUS "Compiler: ${CXX_VERSION_RESULT}")
message(STATUS "Compiler: ${CXX_VERSION_RESULT}, ${CMAKE_CXX_COMPILE_FEATURES}")
20 changes: 16 additions & 4 deletions include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>

#ifdef JSON_HAS_CPP_17
#include <filesystem>
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
#if JSON_STD_FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace nlohmann::detail
#else
#include <filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::filesystem;
} // namespace nlohmann::detail
#endif
#endif

namespace nlohmann
Expand Down Expand Up @@ -448,9 +460,9 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
}
}

#ifdef JSON_HAS_CPP_17
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
template<typename BasicJsonType>
void from_json(const BasicJsonType& j, std::filesystem::path& p)
void from_json(const BasicJsonType& j, std_fs::path& p)
{
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{
Expand Down
20 changes: 16 additions & 4 deletions include/nlohmann/detail/conversions/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>

#ifdef JSON_HAS_CPP_17
#include <filesystem>
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
#if JSON_STD_FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace nlohmann::detail
#else
#include <filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::filesystem;
} // namespace nlohmann::detail
#endif
#endif

namespace nlohmann
Expand Down Expand Up @@ -391,9 +403,9 @@ void to_json(BasicJsonType& j, const T& t)
to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
}

#ifdef JSON_HAS_CPP_17
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
nlohmann marked this conversation as resolved.
Show resolved Hide resolved
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::filesystem::path& p)
void to_json(BasicJsonType& j, const std_fs::path& p)
{
j = p.string();
}
Expand Down
22 changes: 22 additions & 0 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@
#define JSON_HAS_CPP_11
#endif

#ifdef JSON_HAS_CPP_17
// set JSON_STD_FILESYSTEM_EXPERIMENTAL to 1 if <experimental/filesystem> should be taken instead of <filesystem>
#if defined(__cpp_lib_filesystem)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#elif defined(__cpp_lib_experimental_filesystem)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#elif !defined(__has_include)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#elif __has_include(<filesystem>)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#elif __has_include(<experimental/filesystem>)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#else
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#endif

// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
#undef JSON_STD_FILESYSTEM_EXPERIMENTAL
#endif
#endif

// disable documentation warnings on clang
#if defined(__clang__)
#pragma clang diagnostic push
Expand Down
1 change: 1 addition & 0 deletions include/nlohmann/detail/macro_unscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_20
#undef JSON_STD_FILESYSTEM_EXPERIMENTAL
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/meta/cpp_future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct static_const
};

template<typename T>
constexpr T static_const<T>::value;
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)

} // namespace detail
} // namespace nlohmann
65 changes: 56 additions & 9 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,28 @@ using is_detected_convertible =
#define JSON_HAS_CPP_11
#endif

#ifdef JSON_HAS_CPP_17
// set JSON_STD_FILESYSTEM_EXPERIMENTAL to 1 if <experimental/filesystem> should be taken instead of <filesystem>
#if defined(__cpp_lib_filesystem)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#elif defined(__cpp_lib_experimental_filesystem)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#elif !defined(__has_include)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#elif __has_include(<filesystem>)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#elif __has_include(<experimental/filesystem>)
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 1
#else
#define JSON_STD_FILESYSTEM_EXPERIMENTAL 0
#endif

// std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/
#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
#undef JSON_STD_FILESYSTEM_EXPERIMENTAL
#endif
#endif

// disable documentation warnings on clang
#if defined(__clang__)
#pragma clang diagnostic push
Expand Down Expand Up @@ -3298,7 +3320,7 @@ struct static_const
};

template<typename T>
constexpr T static_const<T>::value;
constexpr T static_const<T>::value; // NOLINT(readability-redundant-declaration)

} // namespace detail
} // namespace nlohmann
Expand Down Expand Up @@ -3950,8 +3972,20 @@ T conditional_static_cast(U value)
// #include <nlohmann/detail/value_t.hpp>


#ifdef JSON_HAS_CPP_17
#include <filesystem>
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
#if JSON_STD_FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace nlohmann::detail
#else
#include <filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::filesystem;
} // namespace nlohmann::detail
#endif
#endif

namespace nlohmann
Expand Down Expand Up @@ -4379,9 +4413,9 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
}
}

#ifdef JSON_HAS_CPP_17
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
template<typename BasicJsonType>
void from_json(const BasicJsonType& j, std::filesystem::path& p)
void from_json(const BasicJsonType& j, std_fs::path& p)
{
if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
{
Expand Down Expand Up @@ -4626,8 +4660,20 @@ class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
// #include <nlohmann/detail/value_t.hpp>


#ifdef JSON_HAS_CPP_17
#include <filesystem>
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
#if JSON_STD_FILESYSTEM_EXPERIMENTAL
#include <experimental/filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace nlohmann::detail
#else
#include <filesystem>
namespace nlohmann::detail
{
namespace std_fs = std::filesystem;
} // namespace nlohmann::detail
#endif
#endif

namespace nlohmann
Expand Down Expand Up @@ -5002,9 +5048,9 @@ void to_json(BasicJsonType& j, const T& t)
to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
}

#ifdef JSON_HAS_CPP_17
#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::filesystem::path& p)
void to_json(BasicJsonType& j, const std_fs::path& p)
{
j = p.string();
}
Expand Down Expand Up @@ -26591,6 +26637,7 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_20
#undef JSON_STD_FILESYSTEM_EXPERIMENTAL
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT
Expand Down
42 changes: 42 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ endif()
# one executable for each unit test file
#############################################################################

# check if compiler supports C++17
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if (${feature} STREQUAL cxx_std_17)
set(compiler_supports_cpp_17 TRUE)
endif()
endforeach()
# Clang only supports C++17 starting from Clang 5.0
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
unset(compiler_supports_cpp_17)
endif()

file(GLOB files src/unit-*.cpp)

foreach(file ${files})
Expand All @@ -68,6 +79,37 @@ foreach(file ${files})
target_include_directories(${testcase} PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
target_link_libraries(${testcase} PRIVATE ${NLOHMANN_JSON_TARGET_NAME})

# add a copy with C++17 compilation
if (compiler_supports_cpp_17)
file(READ ${file} FILE_CONTENT)
string(FIND "${FILE_CONTENT}" "JSON_HAS_CPP_17" CPP_17_FOUND)
if(NOT ${CPP_17_FOUND} EQUAL -1)
add_executable(${testcase}_cpp17 $<TARGET_OBJECTS:doctest_main> ${file})
target_compile_definitions(${testcase}_cpp17 PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
target_compile_options(${testcase}_cpp17 PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
)
target_include_directories(${testcase}_cpp17 PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
target_link_libraries(${testcase}_cpp17 PRIVATE ${NLOHMANN_JSON_TARGET_NAME})
target_compile_features(${testcase}_cpp17 PRIVATE cxx_std_17)

if (JSON_FastTests)
add_test(NAME "${testcase}_cpp17"
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else()
add_test(NAME "${testcase}_cpp17"
COMMAND ${testcase}_cpp17 ${DOCTEST_TEST_FILTER} --no-skip
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
set_tests_properties("${testcase}_cpp17" PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA)
endif()
endif()

if (JSON_FastTests)
add_test(NAME "${testcase}"
COMMAND ${testcase} ${DOCTEST_TEST_FILTER}
Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-regression1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ TEST_CASE("regression tests 1")
// check if the actual value was stored
CHECK(j2 == 102);

static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "");
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same");

j.push_back(json::object(
{
Expand Down
Loading