added changes from #105: MSVC fixes

- additionally, switch off optimization flags to maybe allow build to
complete on AppVeyor
This commit is contained in:
Niels 2015-07-16 18:45:19 +02:00
parent e007f02c54
commit 5084159048
4 changed files with 64 additions and 47 deletions

View file

@ -8,7 +8,7 @@ add_executable(json_unit
if(MSVC) if(MSVC)
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS
"/EHsc" "/EHsc /Od"
) )
add_definitions(-D_SCL_SECURE_NO_WARNINGS) add_definitions(-D_SCL_SECURE_NO_WARNINGS)
else(MSVC) else(MSVC)

View file

@ -137,7 +137,7 @@ class basic_json
{ {
private: private:
/// workaround type for MSVC /// workaround type for MSVC
using __basic_json = using basic_json_t =
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>; basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>;
public: public:
@ -890,10 +890,10 @@ class basic_json
*/ */
template <class CompatibleArrayType, typename template <class CompatibleArrayType, typename
std::enable_if< std::enable_if<
not std::is_same<CompatibleArrayType, typename __basic_json::iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::const_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::reverse_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::const_reverse_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
@ -1401,8 +1401,8 @@ class basic_json
*/ */
template <class InputIT, typename template <class InputIT, typename
std::enable_if< std::enable_if<
std::is_same<InputIT, typename __basic_json::iterator>::value or std::is_same<InputIT, typename basic_json_t::iterator>::value or
std::is_same<InputIT, typename __basic_json::const_iterator>::value std::is_same<InputIT, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type) basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
@ -1503,7 +1503,7 @@ class basic_json
@throw std::bad_alloc if allocation for object, array, or string fails. @throw std::bad_alloc if allocation for object, array, or string fails.
@liveexample{The following code shows an example for the copy @liveexample{The following code shows an example for the copy
constructor.,basic_json__basic_json} constructor.,basic_jsonbasic_json_t}
@ingroup container @ingroup container
*/ */
@ -1958,7 +1958,7 @@ class basic_json
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
std::is_convertible<__basic_json, typename T::mapped_type>::value std::is_convertible<basic_json_t, typename T::mapped_type>::value
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
@ -1994,8 +1994,8 @@ class basic_json
/// get an array (explicit) /// get an array (explicit)
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<__basic_json, typename T::value_type>::value and std::is_convertible<basic_json_t, typename T::value_type>::value and
not std::is_same<__basic_json, typename T::value_type>::value and not std::is_same<basic_json_t, typename T::value_type>::value and
not std::is_arithmetic<T>::value and not std::is_arithmetic<T>::value and
not std::is_convertible<std::string, T>::value and not std::is_convertible<std::string, T>::value and
not has_mapped_type<T>::value not has_mapped_type<T>::value
@ -2024,8 +2024,8 @@ class basic_json
/// get an array (explicit) /// get an array (explicit)
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<__basic_json, T>::value and std::is_convertible<basic_json_t, T>::value and
not std::is_same<__basic_json, T>::value not std::is_same<basic_json_t, T>::value
, int>::type = 0> , int>::type = 0>
std::vector<T> get_impl(std::vector<T>*) const std::vector<T> get_impl(std::vector<T>*) const
{ {
@ -2838,8 +2838,8 @@ class basic_json
*/ */
template <class InteratorType, typename template <class InteratorType, typename
std::enable_if< std::enable_if<
std::is_same<InteratorType, typename __basic_json::iterator>::value or std::is_same<InteratorType, typename basic_json_t::iterator>::value or
std::is_same<InteratorType, typename __basic_json::const_iterator>::value std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
InteratorType erase(InteratorType pos) InteratorType erase(InteratorType pos)
@ -2931,8 +2931,8 @@ class basic_json
*/ */
template <class InteratorType, typename template <class InteratorType, typename
std::enable_if< std::enable_if<
std::is_same<InteratorType, typename basic_json::iterator>::value or std::is_same<InteratorType, typename basic_json_t::iterator>::value or
std::is_same<InteratorType, typename basic_json::const_iterator>::value std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
InteratorType erase(InteratorType first, InteratorType last) InteratorType erase(InteratorType first, InteratorType last)
@ -4285,8 +4285,9 @@ class basic_json
} }
// We only reach this line if we cannot compare values. In that case, // We only reach this line if we cannot compare values. In that case,
// we compare types. // we compare types. Note we have to call the operator explicitly,
return lhs_type < rhs_type; // because MSVC has problems otherwise.
return operator<(lhs_type, rhs_type);
} }
/*! /*!
@ -4851,8 +4852,14 @@ class basic_json
difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min(); difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min();
}; };
/// an iterator value /*!
union internal_iterator @brief an iterator value
@note This structure could easily be a union, but MSVC currently does not
allow unions members with complex constructors, see
https://github.com/nlohmann/json/pull/105.
*/
struct internal_iterator
{ {
/// iterator for JSON objects /// iterator for JSON objects
typename object_t::iterator object_iterator; typename object_t::iterator object_iterator;

View file

@ -137,7 +137,7 @@ class basic_json
{ {
private: private:
/// workaround type for MSVC /// workaround type for MSVC
using __basic_json = using basic_json_t =
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>; basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>;
public: public:
@ -890,10 +890,10 @@ class basic_json
*/ */
template <class CompatibleArrayType, typename template <class CompatibleArrayType, typename
std::enable_if< std::enable_if<
not std::is_same<CompatibleArrayType, typename __basic_json::iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::const_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::reverse_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename __basic_json::const_reverse_iterator>::value and not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
@ -1401,8 +1401,8 @@ class basic_json
*/ */
template <class InputIT, typename template <class InputIT, typename
std::enable_if< std::enable_if<
std::is_same<InputIT, typename __basic_json::iterator>::value or std::is_same<InputIT, typename basic_json_t::iterator>::value or
std::is_same<InputIT, typename __basic_json::const_iterator>::value std::is_same<InputIT, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type) basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
@ -1503,7 +1503,7 @@ class basic_json
@throw std::bad_alloc if allocation for object, array, or string fails. @throw std::bad_alloc if allocation for object, array, or string fails.
@liveexample{The following code shows an example for the copy @liveexample{The following code shows an example for the copy
constructor.,basic_json__basic_json} constructor.,basic_jsonbasic_json_t}
@ingroup container @ingroup container
*/ */
@ -1958,7 +1958,7 @@ class basic_json
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<typename object_t::key_type, typename T::key_type>::value and std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
std::is_convertible<__basic_json, typename T::mapped_type>::value std::is_convertible<basic_json_t, typename T::mapped_type>::value
, int>::type = 0> , int>::type = 0>
T get_impl(T*) const T get_impl(T*) const
{ {
@ -1994,8 +1994,8 @@ class basic_json
/// get an array (explicit) /// get an array (explicit)
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<__basic_json, typename T::value_type>::value and std::is_convertible<basic_json_t, typename T::value_type>::value and
not std::is_same<__basic_json, typename T::value_type>::value and not std::is_same<basic_json_t, typename T::value_type>::value and
not std::is_arithmetic<T>::value and not std::is_arithmetic<T>::value and
not std::is_convertible<std::string, T>::value and not std::is_convertible<std::string, T>::value and
not has_mapped_type<T>::value not has_mapped_type<T>::value
@ -2024,8 +2024,8 @@ class basic_json
/// get an array (explicit) /// get an array (explicit)
template <class T, typename template <class T, typename
std::enable_if< std::enable_if<
std::is_convertible<__basic_json, T>::value and std::is_convertible<basic_json_t, T>::value and
not std::is_same<__basic_json, T>::value not std::is_same<basic_json_t, T>::value
, int>::type = 0> , int>::type = 0>
std::vector<T> get_impl(std::vector<T>*) const std::vector<T> get_impl(std::vector<T>*) const
{ {
@ -2838,8 +2838,8 @@ class basic_json
*/ */
template <class InteratorType, typename template <class InteratorType, typename
std::enable_if< std::enable_if<
std::is_same<InteratorType, typename __basic_json::iterator>::value or std::is_same<InteratorType, typename basic_json_t::iterator>::value or
std::is_same<InteratorType, typename __basic_json::const_iterator>::value std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
InteratorType erase(InteratorType pos) InteratorType erase(InteratorType pos)
@ -2931,8 +2931,8 @@ class basic_json
*/ */
template <class InteratorType, typename template <class InteratorType, typename
std::enable_if< std::enable_if<
std::is_same<InteratorType, typename basic_json::iterator>::value or std::is_same<InteratorType, typename basic_json_t::iterator>::value or
std::is_same<InteratorType, typename basic_json::const_iterator>::value std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
, int>::type , int>::type
= 0> = 0>
InteratorType erase(InteratorType first, InteratorType last) InteratorType erase(InteratorType first, InteratorType last)
@ -4285,8 +4285,9 @@ class basic_json
} }
// We only reach this line if we cannot compare values. In that case, // We only reach this line if we cannot compare values. In that case,
// we compare types. // we compare types. Note we have to call the operator explicitly,
return lhs_type < rhs_type; // because MSVC has problems otherwise.
return operator<(lhs_type, rhs_type);
} }
/*! /*!
@ -4851,8 +4852,14 @@ class basic_json
difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min(); difference_type m_it = std::numeric_limits<std::ptrdiff_t>::min();
}; };
/// an iterator value /*!
union internal_iterator @brief an iterator value
@note This structure could easily be a union, but MSVC currently does not
allow unions members with complex constructors, see
https://github.com/nlohmann/json/pull/105.
*/
struct internal_iterator
{ {
/// iterator for JSON objects /// iterator for JSON objects
typename object_t::iterator object_iterator; typename object_t::iterator object_iterator;

View file

@ -6939,7 +6939,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE(i); CAPTURE(i);
CAPTURE(j); CAPTURE(j);
// check precomputed values // check precomputed values
CHECK( (j_types[i] < j_types[j]) == expected[i][j] ); CHECK(operator<(j_types[i], j_types[j]) == expected[i][j]);
} }
} }
} }
@ -8163,9 +8163,11 @@ TEST_CASE("parser class")
SECTION("escaped") SECTION("escaped")
{ {
// quotation mark "\"" // quotation mark "\""
CHECK(json::parser("\"\\\"\"").parse() == R"("\"")"_json); auto r1 = R"("\"")"_json;
CHECK(json::parser("\"\\\"\"").parse() == r1);
// reverse solidus "\\" // reverse solidus "\\"
CHECK(json::parser("\"\\\\\"").parse() == R"("\\")"_json); auto r2 = R"("\\")"_json;
CHECK(json::parser("\"\\\\\"").parse() == r2);
// solidus // solidus
CHECK(json::parser("\"\\/\"").parse() == R"("/")"_json); CHECK(json::parser("\"\\/\"").parse() == R"("/")"_json);
// backspace // backspace
@ -9738,7 +9740,8 @@ TEST_CASE("regression tests")
{ {
auto s = "[\"\\\"foo\\\"\"]"; auto s = "[\"\\\"foo\\\"\"]";
json j = json::parse(s); json j = json::parse(s);
CHECK(j == R"(["\"foo\""])"_json); auto expected = R"(["\"foo\""])"_json;
CHECK(j == expected);
} }
} }