Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
8cec55a2
Unverified
Commit
8cec55a2
authored
Feb 22, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
fixed more warnings
parent
345a106d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
82 additions
and
30 deletions
+82
-30
Makefile
Makefile
+22
-0
src/json.hpp
src/json.hpp
+22
-8
src/json.hpp.re2c
src/json.hpp.re2c
+22
-8
test/src/unit-allocator.cpp
test/src/unit-allocator.cpp
+3
-3
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+1
-1
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+1
-1
test/src/unit-msgpack.cpp
test/src/unit-msgpack.cpp
+2
-2
test/src/unit-readme.cpp
test/src/unit-readme.cpp
+1
-1
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+6
-6
test/src/unit-testsuites.cpp
test/src/unit-testsuites.cpp
+2
-0
No files found.
Makefile
View file @
8cec55a2
...
...
@@ -41,6 +41,28 @@ doctest:
$(MAKE)
check_output
-C
doc
##########################################################################
# warning detector
##########################################################################
# calling Clang with all warnings, except:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in Catch code
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-deprecated-declarations: some functions are deprecated until 3.0.0
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
pedantic
:
$(MAKE)
json_unit
CXXFLAGS
=
"
\
-std=c++11
\
-Werror
\
-Weverything
\
-Wno-documentation-unknown-command
\
-Wno-exit-time-destructors
\
-Wno-keyword-macro
\
-Wno-deprecated-declarations
\
-Wno-range-loop-analysis"
##########################################################################
# fuzzing
##########################################################################
...
...
src/json.hpp
View file @
8cec55a2
...
...
@@ -673,7 +673,7 @@ template<typename BasicJsonType, typename UnscopedEnumType,
enable_if_t
<
is_unscoped_enum
<
UnscopedEnumType
>
::
value
,
int
>
=
0
>
void
from_json
(
const
BasicJsonType
&
j
,
UnscopedEnumType
&
e
)
{
typename
std
::
underlying_type
<
UnscopedEnumType
>::
type
val
=
e
;
typename
std
::
underlying_type
<
UnscopedEnumType
>::
type
val
;
get_arithmetic_value
(
j
,
val
);
e
=
static_cast
<
UnscopedEnumType
>
(
val
);
}
...
...
@@ -917,7 +917,7 @@ struct adl_serializer
@ref basic_json class (either explicit or via conversion operators).
@param[in] j JSON value to read from
@param[in,
out] val value to write to
@param[in,out] val value to write to
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
void
from_json
(
BasicJsonType
&&
j
,
ValueType
&
val
)
noexcept
(
...
...
@@ -932,7 +932,7 @@ struct adl_serializer
This function is usually called by the constructors of the @ref basic_json
class.
@param[in,
out] j JSON value to write to
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
...
...
@@ -6537,6 +6537,11 @@ class basic_json
/// @{
private:
/*!
@note Some code in the switch cases has been copied, because otherwise
copilers would complain about implicit fallthrough and there is no
portable attribute to mute such warnings.
*/
template
<
typename
T
>
static
void
add_to_vector
(
std
::
vector
<
uint8_t
>&
vec
,
size_t
bytes
,
const
T
number
)
{
...
...
@@ -6550,20 +6555,27 @@ class basic_json
vec
.
push_back
(
static_cast
<
uint8_t
>
((
static_cast
<
uint64_t
>
(
number
)
>>
060
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
((
static_cast
<
uint64_t
>
(
number
)
>>
050
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
((
static_cast
<
uint64_t
>
(
number
)
>>
040
)
&
0xff
));
// intentional fall-through
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
030
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
020
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
010
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
(
number
&
0xff
));
break
;
}
case
4
:
{
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
030
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
020
)
&
0xff
));
// intentional fall-through
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
010
)
&
0xff
));
vec
.
push_back
(
static_cast
<
uint8_t
>
(
number
&
0xff
));
break
;
}
case
2
:
{
vec
.
push_back
(
static_cast
<
uint8_t
>
((
number
>>
010
)
&
0xff
));
// intentional fall-through
vec
.
push_back
(
static_cast
<
uint8_t
>
(
number
&
0xff
));
break
;
}
case
1
:
...
...
@@ -7865,7 +7877,9 @@ class basic_json
}
else
{
val
=
mant
==
0
?
INFINITY
:
NAN
;
val
=
mant
==
0
?
std
::
numeric_limits
<
double
>::
infinity
()
:
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
return
(
half
&
0x8000
)
!=
0
?
-
val
:
val
;
}
...
...
@@ -11181,7 +11195,7 @@ basic_json_parser_74:
// of characters determined by the lexer (len)
const
bool
ok
=
(
endptr
==
(
data
+
len
));
if
(
ok
and
(
value
==
0.0
)
and
(
*
data
==
'-'
))
if
(
ok
and
(
value
==
static_cast
<
T
>
(
0.0
)
)
and
(
*
data
==
'-'
))
{
// some implementations forget to negate the zero
value
=
-
0.0
;
...
...
src/json.hpp.re2c
View file @
8cec55a2
...
...
@@ -673,7 +673,7 @@ template<typename BasicJsonType, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void from_json(const BasicJsonType& j, UnscopedEnumType& e)
{
typename std::underlying_type<UnscopedEnumType>::type val
= e
;
typename std::underlying_type<UnscopedEnumType>::type val;
get_arithmetic_value(j, val);
e = static_cast<UnscopedEnumType>(val);
}
...
...
@@ -917,7 +917,7 @@ struct adl_serializer
@ref basic_json class (either explicit or via conversion operators).
@param[in] j JSON value to read from
@param[in,
out] val value to write to
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename ValueType>
static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
...
...
@@ -932,7 +932,7 @@ struct adl_serializer
This function is usually called by the constructors of the @ref basic_json
class.
@param[in,
out] j JSON value to write to
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template<typename BasicJsonType, typename ValueType>
...
...
@@ -6537,6 +6537,11 @@ class basic_json
/// @{
private:
/*!
@note Some code in the switch cases has been copied, because otherwise
copilers would complain about implicit fallthrough and there is no
portable attribute to mute such warnings.
*/
template<typename T>
static void add_to_vector(std::vector<uint8_t>& vec, size_t bytes, const T number)
{
...
...
@@ -6550,20 +6555,27 @@ class basic_json
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 060) & 0xff));
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 050) & 0xff));
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 040) & 0xff));
// intentional fall-through
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
vec.push_back(static_cast<uint8_t>(number & 0xff));
break;
}
case 4:
{
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
// intentional fall-through
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
vec.push_back(static_cast<uint8_t>(number & 0xff));
break;
}
case 2:
{
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
// intentional fall-through
vec.push_back(static_cast<uint8_t>(number & 0xff));
break;
}
case 1:
...
...
@@ -7865,7 +7877,9 @@ class basic_json
}
else
{
val = mant == 0 ? INFINITY : NAN;
val = mant == 0
? std::numeric_limits<double>::infinity()
: std::numeric_limits<double>::quiet_NaN();
}
return (half & 0x8000) != 0 ? -val : val;
}
...
...
@@ -10215,7 +10229,7 @@ class basic_json
// of characters determined by the lexer (len)
const bool ok = (endptr == (data + len));
if (ok and (value ==
0.0
) and (*data == '-'))
if (ok and (value ==
static_cast<T>(0.0)
) and (*data == '-'))
{
// some implementations forget to negate the zero
value = -0.0;
...
...
test/src/unit-allocator.cpp
View file @
8cec55a2
...
...
@@ -63,9 +63,9 @@ TEST_CASE("bad_alloc")
}
}
bool
next_construct_fails
=
false
;
bool
next_destroy_fails
=
false
;
bool
next_deallocate_fails
=
false
;
static
bool
next_construct_fails
=
false
;
static
bool
next_destroy_fails
=
false
;
static
bool
next_deallocate_fails
=
false
;
template
<
class
T
>
struct
my_allocator
:
std
::
allocator
<
T
>
...
...
test/src/unit-cbor.cpp
View file @
8cec55a2
...
...
@@ -237,7 +237,7 @@ TEST_CASE("CBOR")
const
auto
result
=
json
::
to_cbor
(
j
);
CHECK
(
result
==
expected
);
int16_t
restored
=
-
1
-
((
result
[
1
]
<<
8
)
+
result
[
2
]
);
int16_t
restored
=
static_cast
<
int16_t
>
(
-
1
-
((
result
[
1
]
<<
8
)
+
result
[
2
])
);
CHECK
(
restored
==
-
9263
);
// roundtrip
...
...
test/src/unit-constructor1.cpp
View file @
8cec55a2
...
...
@@ -725,7 +725,7 @@ TEST_CASE("constructors")
SECTION
(
"long double"
)
{
long
double
n
=
42.23
;
long
double
n
=
42.23
l
;
json
j
(
n
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
number_float
);
CHECK
(
j
.
m_value
.
number_float
==
Approx
(
j_reference
.
m_value
.
number_float
));
...
...
test/src/unit-msgpack.cpp
View file @
8cec55a2
...
...
@@ -342,7 +342,7 @@ TEST_CASE("MessagePack")
const
auto
result
=
json
::
to_msgpack
(
j
);
CHECK
(
result
==
expected
);
int16_t
restored
=
(
result
[
1
]
<<
8
)
+
result
[
2
]
;
int16_t
restored
=
static_cast
<
int16_t
>
((
result
[
1
]
<<
8
)
+
result
[
2
])
;
CHECK
(
restored
==
-
9263
);
// roundtrip
...
...
@@ -374,7 +374,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK
(
result
[
0
]
==
0xd1
);
int16_t
restored
=
(
result
[
1
]
<<
8
)
+
result
[
2
]
;
int16_t
restored
=
static_cast
<
int16_t
>
((
result
[
1
]
<<
8
)
+
result
[
2
])
;
CHECK
(
restored
==
i
);
// roundtrip
...
...
test/src/unit-readme.cpp
View file @
8cec55a2
...
...
@@ -163,7 +163,7 @@ TEST_CASE("README", "[hide]")
j
.
clear
();
// the array is empty again
// comparison
j
==
"[
\"
foo
\"
, 1, true]"
_json
;
// true
bool
x
=
(
j
==
"[
\"
foo
\"
, 1, true]"
_json
)
;
// true
// create an object
json
o
;
...
...
test/src/unit-regression.cpp
View file @
8cec55a2
...
...
@@ -350,8 +350,8 @@ TEST_CASE("regression tests")
// double
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
int64_t
,
uint64_t
,
double
>
j_double
=
1.23e35
f
;
CHECK
(
j_double
.
get
<
double
>
()
==
1.23e35
f
);
1.23e35
;
CHECK
(
j_double
.
get
<
double
>
()
==
1.23e35
);
// long double
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
int64_t
,
uint64_t
,
long
double
>
...
...
@@ -641,7 +641,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
json
::
from_msgpack
(
vec1
),
std
::
out_of_range
);
// more test cases for MessagePack
for
(
uint8_t
b
:
for
(
auto
b
:
{
0x81
,
0x82
,
0x83
,
0x84
,
0x85
,
0x86
,
0x87
,
0x88
,
0x89
,
0x8a
,
0x8b
,
0x8c
,
0x8d
,
0x8e
,
0x8f
,
// fixmap
0x91
,
0x92
,
0x93
,
0x94
,
0x95
,
0x96
,
0x97
,
0x98
,
0x99
,
0x9a
,
0x9b
,
0x9c
,
0x9d
,
0x9e
,
0x9f
,
// fixarray
...
...
@@ -649,12 +649,12 @@ TEST_CASE("regression tests")
0xb0
,
0xb1
,
0xb2
,
0xb3
,
0xb4
,
0xb5
,
0xb6
,
0xb7
,
0xb8
,
0xb9
,
0xba
,
0xbb
,
0xbc
,
0xbd
,
0xbe
,
0xbf
})
{
std
::
vector
<
uint8_t
>
vec
(
1
,
b
);
std
::
vector
<
uint8_t
>
vec
(
1
,
static_cast
<
uint8_t
>
(
b
)
);
CHECK_THROWS_AS
(
json
::
from_msgpack
(
vec
),
std
::
out_of_range
);
}
// more test cases for CBOR
for
(
uint8_t
b
:
for
(
auto
b
:
{
0x61
,
0x62
,
0x63
,
0x64
,
0x65
,
0x66
,
0x67
,
0x68
,
0x69
,
0x6a
,
0x6b
,
0x6c
,
0x6d
,
0x6e
,
0x6f
,
0x70
,
0x71
,
0x72
,
0x73
,
0x74
,
0x75
,
0x76
,
0x77
,
// UTF-8 string
...
...
@@ -664,7 +664,7 @@ TEST_CASE("regression tests")
0xb0
,
0xb1
,
0xb2
,
0xb3
,
0xb4
,
0xb5
,
0xb6
,
0xb7
// map
})
{
std
::
vector
<
uint8_t
>
vec
(
1
,
b
);
std
::
vector
<
uint8_t
>
vec
(
1
,
static_cast
<
uint8_t
>
(
b
)
);
CHECK_THROWS_AS
(
json
::
from_cbor
(
vec
),
std
::
out_of_range
);
}
...
...
test/src/unit-testsuites.cpp
View file @
8cec55a2
...
...
@@ -816,6 +816,8 @@ TEST_CASE("nst's JSONTestSuite")
}
}
std
::
string
trim
(
const
std
::
string
&
str
);
// from http://stackoverflow.com/a/25829178/266378
std
::
string
trim
(
const
std
::
string
&
str
)
{
...
...
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