Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
057b1e60
Unverified
Commit
057b1e60
authored
Feb 16, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
🔀
merged #415 (fix for #414)
parents
2c17c1b1
6bf93b3d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
82 deletions
+60
-82
README.md
README.md
+2
-2
json.hpp
src/json.hpp
+20
-40
json.hpp.re2c
src/json.hpp.re2c
+20
-40
unit-regression.cpp
test/src/unit-regression.cpp
+18
-0
No files found.
README.md
View file @
057b1e60
...
...
@@ -823,7 +823,7 @@ I deeply appreciate the help of the following people.
- [Martin Hořeňovský](https://github.com/horenmar) found a way for a 2x speedup for the compilation time of the test suite.
- [ukhegg](https://github.com/ukhegg) found proposed an improvement for the examples section.
- [rswanson-ihi](https://github.com/rswanson-ihi) noted a type in the README.
-
-
[Mihai Stan](https://github.com/stanmihai4) fixed a bug in the comparison with `nullptr`s.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
...
...
@@ -857,7 +857,7 @@ $ make json_unit -Ctest
$ ./test/json_unit "
*
""
===============================================================================
All tests passed (112025
62
assertions in 47 test cases)
All tests passed (112025
88
assertions in 47 test cases)
```
Alternatively, you can use [CMake](https://cmake.org) and run
...
...
src/json.hpp
View file @
057b1e60
...
...
@@ -5963,34 +5963,24 @@ class basic_json
/*!
@brief comparison: equal
The functions compares the given JSON value against a null pointer. As the
null pointer can be used to initialize a JSON value to null, a comparison
of JSON value @a v with a null pointer should be equivalent to call
`v.is_null()`.
@param[in] v JSON value to consider
@return whether @a v is null
@complexity Constant.
@liveexample{The example compares several JSON types to the null pointer.
,operator__equal__nullptr_t}
@since version 1.0.0
@copydoc operator==(const_reference, const_reference)
*/
friend
bool
operator
==
(
const_reference
v
,
std
::
nullptr_t
)
noexcept
template
<
typename
ScalarType
,
typename
std
::
enable_if
<
std
::
is_scalar
<
ScalarType
>::
value
,
int
>::
type
=
0
>
friend
bool
operator
==
(
const_reference
lhs
,
const
ScalarType
rhs
)
noexcept
{
return
v
.
is_null
(
);
return
(
lhs
==
basic_json
(
rhs
)
);
}
/*!
@brief comparison: equal
@copydoc operator==(const_reference,
std::nullptr_t
)
@copydoc operator==(const_reference,
const_reference
)
*/
friend
bool
operator
==
(
std
::
nullptr_t
,
const_reference
v
)
noexcept
template
<
typename
ScalarType
,
typename
std
::
enable_if
<
std
::
is_scalar
<
ScalarType
>::
value
,
int
>::
type
=
0
>
friend
bool
operator
==
(
const
ScalarType
lhs
,
const_reference
rhs
)
noexcept
{
return
v
.
is_null
(
);
return
(
basic_json
(
lhs
)
==
rhs
);
}
/*!
...
...
@@ -6016,34 +6006,24 @@ class basic_json
/*!
@brief comparison: not equal
The functions compares the given JSON value against a null pointer. As the
null pointer can be used to initialize a JSON value to null, a comparison
of JSON value @a v with a null pointer should be equivalent to call
`not v.is_null()`.
@param[in] v JSON value to consider
@return whether @a v is not null
@complexity Constant.
@liveexample{The example compares several JSON types to the null pointer.
,operator__notequal__nullptr_t}
@since version 1.0.0
@copydoc operator!=(const_reference, const_reference)
*/
friend
bool
operator
!=
(
const_reference
v
,
std
::
nullptr_t
)
noexcept
template
<
typename
ScalarType
,
typename
std
::
enable_if
<
std
::
is_scalar
<
ScalarType
>::
value
,
int
>::
type
=
0
>
friend
bool
operator
!=
(
const_reference
lhs
,
const
ScalarType
rhs
)
noexcept
{
return
not
v
.
is_null
(
);
return
(
lhs
!=
basic_json
(
rhs
)
);
}
/*!
@brief comparison: not equal
@copydoc operator!=(const_reference,
std::nullptr_t
)
@copydoc operator!=(const_reference,
const_reference
)
*/
friend
bool
operator
!=
(
std
::
nullptr_t
,
const_reference
v
)
noexcept
template
<
typename
ScalarType
,
typename
std
::
enable_if
<
std
::
is_scalar
<
ScalarType
>::
value
,
int
>::
type
=
0
>
friend
bool
operator
!=
(
const
ScalarType
lhs
,
const_reference
rhs
)
noexcept
{
return
not
v
.
is_null
(
);
return
(
basic_json
(
lhs
)
!=
rhs
);
}
/*!
...
...
src/json.hpp.re2c
View file @
057b1e60
...
...
@@ -5963,34 +5963,24 @@ class basic_json
/*!
@brief comparison: equal
The functions compares the given JSON value against a null pointer. As the
null pointer can be used to initialize a JSON value to null, a comparison
of JSON value @a v with a null pointer should be equivalent to call
`v.is_null()`.
@param[in] v JSON value to consider
@return whether @a v is null
@complexity Constant.
@liveexample{The example compares several JSON types to the null pointer.
,operator__equal__nullptr_t}
@since version 1.0.0
@copydoc operator==(const_reference, const_reference)
*/
friend bool operator==(const_reference v, std::nullptr_t) noexcept
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
{
return
v.is_null(
);
return
(lhs == basic_json(rhs)
);
}
/*!
@brief comparison: equal
@copydoc operator==(const_reference,
std::nullptr_t
)
@copydoc operator==(const_reference,
const_reference
)
*/
friend bool operator==(std::nullptr_t, const_reference v) noexcept
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
{
return
v.is_null(
);
return
(basic_json(lhs) == rhs
);
}
/*!
...
...
@@ -6016,34 +6006,24 @@ class basic_json
/*!
@brief comparison: not equal
The functions compares the given JSON value against a null pointer. As the
null pointer can be used to initialize a JSON value to null, a comparison
of JSON value @a v with a null pointer should be equivalent to call
`not v.is_null()`.
@param[in] v JSON value to consider
@return whether @a v is not null
@complexity Constant.
@liveexample{The example compares several JSON types to the null pointer.
,operator__notequal__nullptr_t}
@since version 1.0.0
@copydoc operator!=(const_reference, const_reference)
*/
friend bool operator!=(const_reference v, std::nullptr_t) noexcept
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
{
return
not v.is_null(
);
return
(lhs != basic_json(rhs)
);
}
/*!
@brief comparison: not equal
@copydoc operator!=(const_reference,
std::nullptr_t
)
@copydoc operator!=(const_reference,
const_reference
)
*/
friend bool operator!=(std::nullptr_t, const_reference v) noexcept
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
{
return
not v.is_null(
);
return
(basic_json(lhs) != rhs
);
}
/*!
...
...
test/src/unit-regression.cpp
View file @
057b1e60
...
...
@@ -698,6 +698,24 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
json
::
from_cbor
(
vec3
),
std
::
out_of_range
);
}
SECTION
(
"issue #414 - compare with literal 0)"
)
{
#define CHECK_TYPE(v) \
CHECK((json(v) == v));\
CHECK((v == json(v)));\
CHECK_FALSE((json(v) != v));\
CHECK_FALSE((v != json(v)));
CHECK_TYPE
(
nullptr
);
CHECK_TYPE
(
0
);
CHECK_TYPE
(
0u
);
CHECK_TYPE
(
0L
);
CHECK_TYPE
(
0.0
);
CHECK_TYPE
(
""
);
#undef CHECK_TYPE
}
SECTION
(
"issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)"
)
{
// original test case
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment