mirror of
https://github.com/nlohmann/json.git
synced 2026-09-29 19:20:30 +00:00
Fix CI: include cycle, GCC 4.8 literal operator spacing, and global UDLs off in the JSON_NO_AUTOMATIC_UDLS test
- Suppress clang-tidy misc-header-include-cycle on the intentional mutual include of json.hpp and json_literals.hpp. - Use operator"" _json with a space for GCC 4.8 in the test's detection aliases, as the header does. - Only test the global literal operators when JSON_USE_GLOBAL_UDLS is on. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -6569,6 +6569,7 @@ struct formatter<nlohmann::NLOHMANN_BASIC_JSON_TPL, char> // NOLINT(cert-dcl58-c
|
||||
// Define JSON_NO_AUTOMATIC_UDLS to include <nlohmann/json_literals.hpp> only
|
||||
// where needed.
|
||||
#ifndef JSON_NO_AUTOMATIC_UDLS
|
||||
// NOLINTNEXTLINE(misc-header-include-cycle): json_literals.hpp includes this header
|
||||
#include <nlohmann/json_literals.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstddef> // size_t
|
||||
#include <string> // string
|
||||
|
||||
// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// This header is included at the end of <nlohmann/json.hpp> unless
|
||||
|
||||
@@ -32859,6 +32859,7 @@ struct formatter<nlohmann::NLOHMANN_BASIC_JSON_TPL, char> // NOLINT(cert-dcl58-c
|
||||
// Define JSON_NO_AUTOMATIC_UDLS to include <nlohmann/json_literals.hpp> only
|
||||
// where needed.
|
||||
#ifndef JSON_NO_AUTOMATIC_UDLS
|
||||
// NOLINTNEXTLINE(misc-header-include-cycle): json_literals.hpp includes this header
|
||||
// #include <nlohmann/json_literals.hpp>
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++
|
||||
@@ -32874,6 +32875,7 @@ struct formatter<nlohmann::NLOHMANN_BASIC_JSON_TPL, char> // NOLINT(cert-dcl58-c
|
||||
#include <cstddef> // size_t
|
||||
#include <string> // string
|
||||
|
||||
// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end
|
||||
// #include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstddef> // size_t
|
||||
#include <string> // string
|
||||
|
||||
// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// This header is included at the end of <nlohmann/json.hpp> unless
|
||||
|
||||
@@ -41,11 +41,20 @@ namespace
|
||||
// deferred to the point of instantiation, where it considers the declarations
|
||||
// visible from here (the global using-declarations of JSON_USE_GLOBAL_UDLS) plus
|
||||
// argument-dependent lookup (the literals in the library namespace).
|
||||
template<typename T>
|
||||
using json_udl_t = decltype(operator""_json(std::declval<T>(), std::size_t()));
|
||||
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
||||
template<typename T>
|
||||
using json_udl_t = decltype(operator""_json(std::declval<T>(), std::size_t()));
|
||||
|
||||
template<typename T>
|
||||
using json_pointer_udl_t = decltype(operator""_json_pointer(std::declval<T>(), std::size_t()));
|
||||
template<typename T>
|
||||
using json_pointer_udl_t = decltype(operator""_json_pointer(std::declval<T>(), std::size_t()));
|
||||
#else
|
||||
// GCC 4.8 requires a space between "" and suffix
|
||||
template<typename T>
|
||||
using json_udl_t = decltype(operator"" _json(std::declval<T>(), std::size_t()));
|
||||
|
||||
template<typename T>
|
||||
using json_pointer_udl_t = decltype(operator"" _json_pointer(std::declval<T>(), std::size_t()));
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
using has_json_udl = nlohmann::detail::is_detected<json_udl_t, T>;
|
||||
@@ -83,11 +92,13 @@ TEST_CASE("JSON_NO_AUTOMATIC_UDLS")
|
||||
|
||||
TEST_CASE("JSON_NO_AUTOMATIC_UDLS with <nlohmann/json_literals.hpp>")
|
||||
{
|
||||
#if !defined(JSON_USE_GLOBAL_UDLS) || JSON_USE_GLOBAL_UDLS
|
||||
SECTION("global namespace")
|
||||
{
|
||||
CHECK("[1,2]"_json == json({1, 2}));
|
||||
CHECK("/a/0"_json_pointer == json::json_pointer("/a/0"));
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("nlohmann::literals::json_literals")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user