🚨 add new CI and fix warnings (#2561)

* ⚗️ move CI targets to CMake
* ♻️ add target for cpplint
* ♻️ add target for self-contained binaries
* ♻️ add targets for iwyu and infer
* 🔊 add version output
* ♻️ add target for oclint
* 🚨 fix warnings
* ♻️ rename targets
* ♻️ use iwyu properly
* 🚨 fix warnings
* ♻️ use iwyu properly
* ♻️ add target for benchmarks
* ♻️ add target for CMake flags
* 👷 use GitHub Actions
* ⚗️ try to install Clang 11
* ⚗️ try to install GCC 11
* ⚗️ try to install Clang 11
* ⚗️ try to install GCC 11
* ⚗️ add clang analyze target
* 🔥 remove Google Benchmark
* ⬆️ Google Benchmark 1.5.2
* 🔥 use fetchcontent
* 🐧 add target to download a Linux version of CMake
* 🔨 fix dependency
* 🚨 fix includes
* 🚨 fix comment
* 🔧 adjust flags for GCC 11.0.0 20210110 (experimental)
* 🐳 user Docker image to run CI
* 🔧 add target for Valgrind
* 👷 add target for Valgrind tests
* ⚗️ add Dart
*  remove Dart
* ⚗️ do not call ctest in test subdirectory
* ⚗️ download test data explicitly
* ⚗️ only execute Valgrind tests
* ⚗️ fix labels
* 🔥 remove unneeded jobs
* 🔨 cleanup
* 🐛 fix OCLint call
*  add targets for offline and git-independent tests
*  add targets for C++ language versions and reproducible tests
* 🔨 clean up
* 👷 add CI steps for cppcheck and cpplint
* 🚨 fix warnings from Clang-Tidy
* 👷 add CI steps for Clang-Tidy
* 🚨 fix warnings
* 🔧 select proper binary
* 🚨 fix warnings
* 🚨 suppress some unhelpful warnings
* 🚨 fix warnings
* 🎨 fix format
* 🚨 fix warnings
* 👷 add CI steps for Sanitizers
* 🚨 fix warnings
*  add optimization to sanitizer build
* 🚨 fix warnings
* 🚨 add missing header
* 🚨 fix warnings
* 👷 add CI step for coverage
* 👷 add CI steps for disabled exceptions and implicit conversions
* 🚨 fix warnings
* 👷 add CI steps for checking indentation
* 🐛 fix variable use
* 💚 fix build
*  remove CircleCI
* 👷 add CI step for diagnostics
* 🚨 fix warning
* 🔥 clean Travis
This commit is contained in:
Niels Lohmann
2021-03-24 07:15:18 +01:00
committed by GitHub
parent 6b74772fe8
commit 6f551930e5
152 changed files with 2494 additions and 12148 deletions

View File

@@ -32,10 +32,11 @@ SOFTWARE.
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <array>
#include <map>
#include <memory>
#include <string>
#include <memory>
#include <utility>
namespace udt
{
@@ -55,40 +56,40 @@ struct age
struct name
{
std::string m_val;
name(const std::string rhs = "") : m_val(rhs) {}
name(std::string rhs = "") : m_val(std::move(rhs)) {}
};
struct address
{
std::string m_val;
address(const std::string rhs = "") : m_val(rhs) {}
address(std::string rhs = "") : m_val(std::move(rhs)) {}
};
struct person
{
age m_age;
name m_name;
country m_country;
person() : m_age(), m_name(), m_country() {}
person(const age& a, const name& n, const country& c) : m_age(a), m_name(n), m_country(c) {}
age m_age{};
name m_name{};
country m_country{};
person() = default;
person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {}
};
struct contact
{
person m_person;
address m_address;
contact() : m_person(), m_address() {}
contact(const person& p, const address& a) : m_person(p), m_address(a) {}
person m_person{};
address m_address{};
contact() = default;
contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {}
};
struct contact_book
{
name m_book_name;
std::vector<contact> m_contacts;
contact_book() : m_book_name(), m_contacts() {}
contact_book(const name& n, const std::vector<contact>& c) : m_book_name(n), m_contacts(c) {}
name m_book_name{};
std::vector<contact> m_contacts{};
contact_book() = default;
contact_book(name n, std::vector<contact> c) : m_book_name(std::move(n)), m_contacts(std::move(c)) {}
};
}
} // namespace udt
// to_json methods
namespace udt
@@ -178,7 +179,7 @@ static bool operator==(const contact_book& lhs, const contact_book& rhs)
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
std::tie(rhs.m_book_name, rhs.m_contacts);
}
}
} // namespace udt
// from_json methods
namespace udt
@@ -199,7 +200,7 @@ template <typename BasicJsonType>
static void from_json(const BasicJsonType& j, country& c)
{
const auto str = j.template get<std::string>();
static const std::map<std::string, country> m =
const std::map<std::string, country> m =
{
{"中华人民共和国", country::china},
{"France", country::france},
@@ -207,7 +208,7 @@ static void from_json(const BasicJsonType& j, country& c)
};
const auto it = m.find(str);
// TODO test exceptions
// TODO(nlohmann) test exceptions
c = it->second;
}
@@ -235,7 +236,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
cb.m_book_name = j["name"].get<name>();
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
}
}
} // namespace udt
TEST_CASE("basic usage" * doctest::test_suite("udt"))
{
@@ -344,11 +345,11 @@ namespace udt
{
struct legacy_type
{
std::string number;
legacy_type() : number() {}
legacy_type(const std::string& n) : number(n) {}
std::string number{};
legacy_type() = default;
legacy_type(std::string n) : number(std::move(n)) {}
};
}
} // namespace udt
namespace nlohmann
{
@@ -375,7 +376,7 @@ struct adl_serializer<std::shared_ptr<T>>
}
else
{
opt.reset(new T(j.get<T>()));
opt.reset(new T(j.get<T>())); // NOLINT(cppcoreguidelines-owning-memory)
}
}
};
@@ -393,7 +394,7 @@ struct adl_serializer<udt::legacy_type>
l.number = std::to_string(j.get<int>());
}
};
}
} // namespace nlohmann
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
{
@@ -406,7 +407,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
json j = optPerson;
CHECK(j.is_null());
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared)
j = optPerson;
CHECK_FALSE(j.is_null());
@@ -453,23 +454,23 @@ template <>
struct adl_serializer<std::vector<float>>
{
using type = std::vector<float>;
static void to_json(json& j, const type&)
static void to_json(json& j, const type& /*type*/)
{
j = "hijacked!";
}
static void from_json(const json&, type& opt)
static void from_json(const json& /*unnamed*/, type& opt)
{
opt = {42.0, 42.0, 42.0};
}
// preferred version
static type from_json(const json&)
static type from_json(const json& /*unnamed*/)
{
return {4.0, 5.0, 6.0};
}
};
}
} // namespace nlohmann
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
{
@@ -504,13 +505,11 @@ struct adl_serializer<std::unique_ptr<T>>
{
return nullptr;
}
else
{
return std::unique_ptr<T>(new T(j.get<T>()));
}
return std::unique_ptr<T>(new T(j.get<T>()));
}
};
}
} // namespace nlohmann
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
{
@@ -521,7 +520,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
json j = optPerson;
CHECK(j.is_null());
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique)
j = optPerson;
CHECK_FALSE(j.is_null());
@@ -566,8 +565,8 @@ struct pod_serializer
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
static void from_json(const BasicJsonType& j, U& t)
{
std::uint64_t value;
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
std::uint64_t value = 0;
// The following block is no longer relevant in this serializer, make another one that shows the issue
// the problem arises only when one from_json method is defined without any constraint
//
// Why cannot we simply use: j.get<std::uint64_t>() ?
@@ -582,7 +581,7 @@ struct pod_serializer
// calling get calls from_json, for now, we cannot do this in custom
// serializers
nlohmann::from_json(j, value);
auto bytes = static_cast<char*>(static_cast<void*>(&value));
auto* bytes = static_cast<char*>(static_cast<void*>(&value));
std::memcpy(&t, bytes, sizeof(value));
}
@@ -601,8 +600,8 @@ struct pod_serializer
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
static void to_json(BasicJsonType& j, const T& t) noexcept
{
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
std::uint64_t value;
const auto* bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
std::uint64_t value = 0;
std::memcpy(&value, bytes, sizeof(value));
nlohmann::to_json(j, value);
}
@@ -619,9 +618,9 @@ struct small_pod
struct non_pod
{
std::string s;
non_pod() : s() {}
non_pod(const std::string& S) : s(S) {}
std::string s{};
non_pod() = default;
non_pod(std::string S) : s(std::move(S)) {}
};
template <typename BasicJsonType>
@@ -651,7 +650,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
{
return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end;
}
}
} // namespace udt
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
{
@@ -803,7 +802,7 @@ struct is_constructible_patched : std::false_type {};
template <typename T>
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
}
} // namespace
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
{
@@ -822,8 +821,8 @@ class Evil
int m_i = 0;
};
void from_json(const json&, Evil&) {}
}
void from_json(const json& /*unused*/, Evil& /*unused*/) {}
} // namespace
TEST_CASE("Issue #924")
{