Fix C++20/gcc-12 issues (Part 1) (#3379)

* 🔧 use proper GCC binary

* 🔧 add more GCC warning flags

* ⚗️ try fix from https://github.com/nlohmann/json/issues/3138#issuecomment-1015562666

* Fix custom allocator test build failures (C++20)

Allocator tests fail to compile in C++20 mode with clang+MS STL due
to missing copy constructors.

* Fix test build failures due to missing noexcept (gcc-12)

* alt_string has multiple member functions that should be marked noexcept.
* nlohmann::ordered_map constructors can be noexcept.

Compilation failures result from the warning flag -Werror=noexcept and
gcc-12.

* Disable broken comparison tests in C++20 mode

Co-authored-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Florian Albrechtskirchinger
2022-03-07 22:19:28 +01:00
committed by GitHub
parent 4a6e6ca8c7
commit f208a9c19b
8 changed files with 47 additions and 13 deletions

View File

@@ -39,6 +39,8 @@ namespace
template<class T>
struct bad_allocator : std::allocator<T>
{
using std::allocator<T>::allocator;
template<class... Args>
void construct(T* /*unused*/, Args&& ... /*unused*/)
{

View File

@@ -104,12 +104,12 @@ class alt_string
}
template <typename op_type>
bool operator<(const op_type& op) const
bool operator<(const op_type& op) const noexcept
{
return str_impl < op;
}
bool operator<(const alt_string& op) const
bool operator<(const alt_string& op) const noexcept
{
return str_impl < op.str_impl;
}

View File

@@ -32,6 +32,10 @@ SOFTWARE.
#include <nlohmann/json.hpp>
using nlohmann::json;
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#define JSON_HAS_CPP_20
#endif
namespace
{
// helper function to check std::less<json::value_t>
@@ -205,6 +209,14 @@ TEST_CASE("lexicographical comparison operators")
{
for (size_t j = 0; j < j_values.size(); ++j)
{
// Skip comparing indicies 12 and 13, and 13 and 12 in C++20 pending fix
// See issue #3207
#ifdef JSON_HAS_CPP_20
if ((i == 12 && j == 13) || (i == 13 && j == 12))
{
continue;
}
#endif
CAPTURE(i)
CAPTURE(j)
CAPTURE(j_values[i])

View File

@@ -271,7 +271,10 @@ std::string* sax_no_exception::error_string = nullptr;
template<class T>
class my_allocator : public std::allocator<T>
{};
{
public:
using std::allocator<T>::allocator;
};
/////////////////////////////////////////////////////////////////////
// for #3077
@@ -338,7 +341,7 @@ TEST_CASE("regression tests 2")
]
})";
json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed)
json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed) noexcept
{
// skip uninteresting events
if (event == json::parse_event_t::value && !parsed.is_primitive())