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
28e20bd9
Unverified
Commit
28e20bd9
authored
May 16, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚨
fix warnings #2113
parent
f40a9f87
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
20 deletions
+47
-20
Makefile
Makefile
+9
-5
binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+1
-1
binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+3
-3
json.hpp
single_include/nlohmann/json.hpp
+4
-4
unit-cbor.cpp
test/src/unit-cbor.cpp
+4
-4
unit-noexcept.cpp
test/src/unit-noexcept.cpp
+16
-1
unit-udt.cpp
test/src/unit-udt.cpp
+9
-1
doctest.h
test/thirdparty/doctest/doctest.h
+1
-1
No files found.
Makefile
View file @
28e20bd9
...
@@ -102,7 +102,8 @@ doctest:
...
@@ -102,7 +102,8 @@ doctest:
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
pedantic_clang
:
pedantic_clang
:
$(MAKE)
json_unit
CXX
=
c++
CXXFLAGS
=
"
\
rm
-fr
build_pedantic
CXXFLAGS
=
"
\
-std=c++11 -Wno-c++98-compat -Wno-c++98-compat-pedantic
\
-std=c++11 -Wno-c++98-compat -Wno-c++98-compat-pedantic
\
-Werror
\
-Werror
\
-Weverything
\
-Weverything
\
...
@@ -115,11 +116,13 @@ pedantic_clang:
...
@@ -115,11 +116,13 @@ pedantic_clang:
-Wno-padded
\
-Wno-padded
\
-Wno-range-loop-analysis
\
-Wno-range-loop-analysis
\
-Wno-switch-enum -Wno-covered-switch-default
\
-Wno-switch-enum -Wno-covered-switch-default
\
-Wno-weak-vtables"
-Wno-weak-vtables"
cmake
-S
.
-B
build_pedantic
-GNinja
-DCMAKE_BUILD_TYPE
=
Debug
-DJSON_MultipleHeaders
=
ON
cmake
--build
build_pedantic
# calling GCC with most warnings
# calling GCC with most warnings
pedantic_gcc
:
pedantic_gcc
:
$(MAKE)
json_unit
CXX
=
/usr/local/bin/g++-9
CXXFLAGS
=
"
\
rm
-fr
build_pedantic
CXXFLAGS
=
"
\
-std=c++11
\
-std=c++11
\
-Waddress
\
-Waddress
\
-Waddress-of-packed-member
\
-Waddress-of-packed-member
\
...
@@ -233,7 +236,7 @@ pedantic_gcc:
...
@@ -233,7 +236,7 @@ pedantic_gcc:
-Wno-system-headers
\
-Wno-system-headers
\
-Wno-templates
\
-Wno-templates
\
-Wno-undef
\
-Wno-undef
\
-Wnoexcept
\
-Wno
-no
except
\
-Wnoexcept-type
\
-Wnoexcept-type
\
-Wnon-template-friend
\
-Wnon-template-friend
\
-Wnon-virtual-dtor
\
-Wnon-virtual-dtor
\
...
@@ -340,7 +343,8 @@ pedantic_gcc:
...
@@ -340,7 +343,8 @@ pedantic_gcc:
-Wvolatile-register-var
\
-Wvolatile-register-var
\
-Wwrite-strings
\
-Wwrite-strings
\
-Wzero-as-null-pointer-constant
\
-Wzero-as-null-pointer-constant
\
"
"
cmake
-S
.
-B
build_pedantic
-GNinja
-DCMAKE_BUILD_TYPE
=
Debug
-DJSON_MultipleHeaders
=
ON
cmake
--build
build_pedantic
##########################################################################
##########################################################################
# benchmarks
# benchmarks
...
...
include/nlohmann/detail/input/binary_reader.hpp
View file @
28e20bd9
...
@@ -32,7 +32,7 @@ namespace detail
...
@@ -32,7 +32,7 @@ namespace detail
@note from https://stackoverflow.com/a/1001328/266378
@note from https://stackoverflow.com/a/1001328/266378
*/
*/
static
bool
little_endianess
(
int
num
=
1
)
noexcept
static
inline
bool
little_endianess
(
int
num
=
1
)
noexcept
{
{
return
*
reinterpret_cast
<
char
*>
(
&
num
)
==
1
;
return
*
reinterpret_cast
<
char
*>
(
&
num
)
==
1
;
}
}
...
...
include/nlohmann/detail/output/binary_writer.hpp
View file @
28e20bd9
...
@@ -194,9 +194,9 @@ class binary_writer
...
@@ -194,9 +194,9 @@ class binary_writer
}
}
else
else
{
{
if
(
j
.
m_value
.
number_float
>=
std
::
numeric_limits
<
float
>::
lowest
(
)
and
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
()
)
and
j
.
m_value
.
number_float
<=
std
::
numeric_limits
<
float
>::
max
(
)
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
max
()
)
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
j
.
m_value
.
number_float
)
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
)
{
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
...
...
single_include/nlohmann/json.hpp
View file @
28e20bd9
...
@@ -5596,7 +5596,7 @@ namespace detail
...
@@ -5596,7 +5596,7 @@ namespace detail
@note from https://stackoverflow.com/a/1001328/266378
@note from https://stackoverflow.com/a/1001328/266378
*/
*/
static
bool
little_endianess
(
int
num
=
1
)
noexcept
static
inline
bool
little_endianess
(
int
num
=
1
)
noexcept
{
{
return
*
reinterpret_cast
<
char
*>
(
&
num
)
==
1
;
return
*
reinterpret_cast
<
char
*>
(
&
num
)
==
1
;
}
}
...
@@ -12188,9 +12188,9 @@ class binary_writer
...
@@ -12188,9 +12188,9 @@ class binary_writer
}
}
else
else
{
{
if
(
j
.
m_value
.
number_float
>=
std
::
numeric_limits
<
float
>::
lowest
(
)
and
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
()
)
and
j
.
m_value
.
number_float
<=
std
::
numeric_limits
<
float
>::
max
(
)
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
max
()
)
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
j
.
m_value
.
number_float
)
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
)
{
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
...
...
test/src/unit-cbor.cpp
View file @
28e20bd9
...
@@ -939,7 +939,7 @@ TEST_CASE("CBOR")
...
@@ -939,7 +939,7 @@ TEST_CASE("CBOR")
}
}
SECTION
(
"-3.40282e+38(lowest float)"
)
SECTION
(
"-3.40282e+38(lowest float)"
)
{
{
double
v
=
st
d
::
numeric_limits
<
float
>::
lowest
(
);
double
v
=
st
atic_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
()
);
json
j
=
v
;
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
std
::
vector
<
uint8_t
>
expected
=
{
{
...
@@ -953,7 +953,7 @@ TEST_CASE("CBOR")
...
@@ -953,7 +953,7 @@ TEST_CASE("CBOR")
}
}
SECTION
(
"1 + 3.40282e+38(more than max float)"
)
SECTION
(
"1 + 3.40282e+38(more than max float)"
)
{
{
double
v
=
st
d
::
numeric_limits
<
float
>::
max
(
)
+
0.1e+34
;
double
v
=
st
atic_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
max
()
)
+
0.1e+34
;
json
j
=
v
;
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
std
::
vector
<
uint8_t
>
expected
=
{
{
...
@@ -968,7 +968,7 @@ TEST_CASE("CBOR")
...
@@ -968,7 +968,7 @@ TEST_CASE("CBOR")
}
}
SECTION
(
"-1 - 3.40282e+38(less than lowest float)"
)
SECTION
(
"-1 - 3.40282e+38(less than lowest float)"
)
{
{
double
v
=
st
d
::
numeric_limits
<
float
>::
lowest
()
-
1
;
double
v
=
st
atic_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
-
1.0
;
json
j
=
v
;
json
j
=
v
;
std
::
vector
<
uint8_t
>
expected
=
std
::
vector
<
uint8_t
>
expected
=
{
{
...
@@ -1582,7 +1582,7 @@ TEST_CASE("CBOR")
...
@@ -1582,7 +1582,7 @@ TEST_CASE("CBOR")
auto
j
=
json
::
from_cbor
(
input
);
auto
j
=
json
::
from_cbor
(
input
);
CHECK
(
j
.
is_binary
());
CHECK
(
j
.
is_binary
());
auto
k
=
json
::
binary_array
({
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
,
0x99
});
auto
k
=
json
::
binary_array
({
0xaa
,
0xbb
,
0xcc
,
0xdd
,
0xee
,
0xff
,
0x99
});
CAPTURE
(
j
.
dump
(
0
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
))
;
CAPTURE
(
j
.
dump
(
0
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
))
CHECK
(
j
==
k
);
CHECK
(
j
==
k
);
}
}
...
...
test/src/unit-noexcept.cpp
View file @
28e20bd9
...
@@ -46,7 +46,12 @@ void to_json(json&, pod) noexcept;
...
@@ -46,7 +46,12 @@ void to_json(json&, pod) noexcept;
void
to_json
(
json
&
,
pod_bis
);
void
to_json
(
json
&
,
pod_bis
);
void
from_json
(
const
json
&
,
pod
)
noexcept
;
void
from_json
(
const
json
&
,
pod
)
noexcept
;
void
from_json
(
const
json
&
,
pod_bis
);
void
from_json
(
const
json
&
,
pod_bis
);
static
json
*
j
;
void
to_json
(
json
&
,
pod
)
noexcept
{}
void
to_json
(
json
&
,
pod_bis
)
{}
void
from_json
(
const
json
&
,
pod
)
noexcept
{}
void
from_json
(
const
json
&
,
pod_bis
)
{}
static
json
*
j
=
nullptr
;
static_assert
(
noexcept
(
json
{}),
""
);
static_assert
(
noexcept
(
json
{}),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
2
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
2
)),
""
);
...
@@ -79,4 +84,14 @@ TEST_CASE("runtime checks")
...
@@ -79,4 +84,14 @@ TEST_CASE("runtime checks")
CHECK
(
std
::
is_nothrow_copy_constructible
<
json
::
out_of_range
>::
value
==
std
::
is_nothrow_copy_constructible
<
std
::
runtime_error
>::
value
);
CHECK
(
std
::
is_nothrow_copy_constructible
<
json
::
out_of_range
>::
value
==
std
::
is_nothrow_copy_constructible
<
std
::
runtime_error
>::
value
);
CHECK
(
std
::
is_nothrow_copy_constructible
<
json
::
other_error
>::
value
==
std
::
is_nothrow_copy_constructible
<
std
::
runtime_error
>::
value
);
CHECK
(
std
::
is_nothrow_copy_constructible
<
json
::
other_error
>::
value
==
std
::
is_nothrow_copy_constructible
<
std
::
runtime_error
>::
value
);
}
}
SECTION
(
"silence -Wunneeded-internal-declaration errors"
)
{
j
=
nullptr
;
json
j2
;
to_json
(
j2
,
pod
());
to_json
(
j2
,
pod_bis
());
from_json
(
j2
,
pod
());
from_json
(
j2
,
pod_bis
());
}
}
}
test/src/unit-udt.cpp
View file @
28e20bd9
...
@@ -120,6 +120,8 @@ static void to_json(BasicJsonType& j, country c)
...
@@ -120,6 +120,8 @@ static void to_json(BasicJsonType& j, country c)
case
country
:
:
russia
:
case
country
:
:
russia
:
j
=
u8"Российская Федерация"
;
j
=
u8"Российская Федерация"
;
return
;
return
;
default
:
break
;
}
}
}
}
...
@@ -803,7 +805,9 @@ class Evil
...
@@ -803,7 +805,9 @@ class Evil
public
:
public
:
Evil
()
=
default
;
Evil
()
=
default
;
template
<
typename
T
>
template
<
typename
T
>
Evil
(
T
)
{}
Evil
(
T
t
)
:
m_i
(
sizeof
(
t
))
{}
int
m_i
=
0
;
};
};
void
from_json
(
const
json
&
,
Evil
&
)
{}
void
from_json
(
const
json
&
,
Evil
&
)
{}
...
@@ -816,6 +820,10 @@ TEST_CASE("Issue #924")
...
@@ -816,6 +820,10 @@ TEST_CASE("Issue #924")
CHECK_NOTHROW
(
j
.
get
<
Evil
>
());
CHECK_NOTHROW
(
j
.
get
<
Evil
>
());
CHECK_NOTHROW
(
j
.
get
<
std
::
vector
<
Evil
>>
());
CHECK_NOTHROW
(
j
.
get
<
std
::
vector
<
Evil
>>
());
// silence Wunused-template warnings
Evil
e
(
1
);
CHECK
(
e
.
m_i
>=
0
);
}
}
TEST_CASE
(
"Issue #1237"
)
TEST_CASE
(
"Issue #1237"
)
...
...
test/thirdparty/doctest/doctest.h
View file @
28e20bd9
...
@@ -2913,7 +2913,7 @@ typedef timer_large_integer::type ticks_t;
...
@@ -2913,7 +2913,7 @@ typedef timer_large_integer::type ticks_t;
//unsigned int getElapsedMilliseconds() const {
//unsigned int getElapsedMilliseconds() const {
// return static_cast<unsigned int>(getElapsedMicroseconds() / 1000);
// return static_cast<unsigned int>(getElapsedMicroseconds() / 1000);
//}
//}
double
getElapsedSeconds
()
const
{
return
(
getCurrentTicks
()
-
m_ticks
)
/
1000000
.
0
;
}
double
getElapsedSeconds
()
const
{
return
static_cast
<
double
>
((
getCurrentTicks
()
-
m_ticks
)
)
/
1000000
.
0
;
}
private
:
private
:
ticks_t
m_ticks
=
0
;
ticks_t
m_ticks
=
0
;
...
...
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