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
9ed027ac
Unverified
Commit
9ed027ac
authored
Jul 31, 2021
by
Niels Lohmann
Committed by
GitHub
Jul 31, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2902 from nlohmann/issue2893
Fix useless-cast warnings
parents
a5633380
f4716a0d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
19 deletions
+50
-19
cmake/ci.cmake
cmake/ci.cmake
+1
-1
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+3
-2
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+14
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+18
-2
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+14
-14
No files found.
cmake/ci.cmake
View file @
9ed027ac
...
...
@@ -356,7 +356,7 @@ set(GCC_CXXFLAGS "-std=c++11 \
-Wunused-result \
-Wunused-value \
-Wunused-variable \
-W
no-
useless-cast \
-Wuseless-cast \
-Wvarargs \
-Wvariadic-macros \
-Wvector-operation-performance \
...
...
include/nlohmann/detail/input/binary_reader.hpp
View file @
9ed027ac
...
...
@@ -19,6 +19,7 @@
#include <nlohmann/detail/input/lexer.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>
namespace
nlohmann
...
...
@@ -631,7 +632,7 @@ class binary_reader
case
0x9B
:
// array (eight-byte uint64_t for n follow)
{
std
::
uint64_t
len
{};
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_array
(
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_array
(
detail
::
conditional_
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
}
case
0x9F
:
// array (indefinite length)
...
...
@@ -685,7 +686,7 @@ class binary_reader
case
0xBB
:
// map (eight-byte uint64_t for n follow)
{
std
::
uint64_t
len
{};
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_object
(
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_object
(
detail
::
conditional_
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
}
case
0xBF
:
// map (indefinite length)
...
...
include/nlohmann/detail/meta/type_traits.hpp
View file @
9ed027ac
...
...
@@ -435,5 +435,19 @@ struct is_constructible_tuple : std::false_type {};
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
is_constructible
<
T1
,
Args
>
...
>
{};
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
template
<
typename
T
,
typename
U
,
enable_if_t
<
!
std
::
is_same
<
T
,
U
>
::
value
,
int
>
=
0
>
T
conditional_static_cast
(
U
value
)
{
return
static_cast
<
T
>
(
value
);
}
template
<
typename
T
,
typename
U
,
enable_if_t
<
std
::
is_same
<
T
,
U
>
::
value
,
int
>
=
0
>
T
conditional_static_cast
(
U
value
)
{
return
value
;
}
}
// namespace detail
}
// namespace nlohmann
single_include/nlohmann/json.hpp
View file @
9ed027ac
...
...
@@ -3835,6 +3835,20 @@ struct is_constructible_tuple : std::false_type {};
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
is_constructible
<
T1
,
Args
>
...
>
{};
// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324)
template
<
typename
T
,
typename
U
,
enable_if_t
<
!
std
::
is_same
<
T
,
U
>
::
value
,
int
>
=
0
>
T
conditional_static_cast
(
U
value
)
{
return
static_cast
<
T
>
(
value
);
}
template
<
typename
T
,
typename
U
,
enable_if_t
<
std
::
is_same
<
T
,
U
>
::
value
,
int
>
=
0
>
T
conditional_static_cast
(
U
value
)
{
return
value
;
}
}
// namespace detail
}
// namespace nlohmann
...
...
@@ -8240,6 +8254,8 @@ struct is_sax_static_asserts
}
// namespace detail
}
// namespace nlohmann
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/value_t.hpp>
...
...
@@ -8853,7 +8869,7 @@ class binary_reader
case
0x9B
:
// array (eight-byte uint64_t for n follow)
{
std
::
uint64_t
len
{};
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_array
(
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_array
(
detail
::
conditional_
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
}
case
0x9F
:
// array (indefinite length)
...
...
@@ -8907,7 +8923,7 @@ class binary_reader
case
0xBB
:
// map (eight-byte uint64_t for n follow)
{
std
::
uint64_t
len
{};
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_object
(
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
return
get_number
(
input_format_t
::
cbor
,
len
)
&&
get_cbor_object
(
detail
::
conditional_
static_cast
<
std
::
size_t
>
(
len
),
tag_handler
);
}
case
0xBF
:
// map (indefinite length)
...
...
test/src/unit-class_parser.cpp
View file @
9ed027ac
...
...
@@ -1381,7 +1381,7 @@ TEST_CASE("parser class")
case
(
'r'
):
case
(
't'
):
{
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s
)
)).
accept
());
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
)).
accept
());
break
;
}
...
...
@@ -1394,7 +1394,7 @@ TEST_CASE("parser class")
// any other combination of backslash and character is invalid
default:
{
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s
)
)).
accept
()
==
false
);
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
)).
accept
()
==
false
);
break
;
}
}
...
...
@@ -1445,35 +1445,35 @@ TEST_CASE("parser class")
std
::
string
s
=
"
\"\\
u"
;
// create a string with the iterated character at each position
auto
s1
=
s
+
"000"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"
\"
"
;
auto
s2
=
s
+
"00"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"0
\"
"
;
auto
s3
=
s
+
"0"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"00
\"
"
;
auto
s4
=
s
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"000
\"
"
;
const
auto
s1
=
s
+
"000"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"
\"
"
;
const
auto
s2
=
s
+
"00"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"0
\"
"
;
const
auto
s3
=
s
+
"0"
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"00
\"
"
;
const
auto
s4
=
s
+
std
::
string
(
1
,
static_cast
<
char
>
(
c
))
+
"000
\"
"
;
if
(
valid
(
c
))
{
CAPTURE
(
s1
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s1
)
)).
accept
());
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
1
)).
accept
());
CAPTURE
(
s2
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s2
)
)).
accept
());
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
2
)).
accept
());
CAPTURE
(
s3
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s3
)
)).
accept
());
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
3
)).
accept
());
CAPTURE
(
s4
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s4
)
)).
accept
());
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
4
)).
accept
());
}
else
{
CAPTURE
(
s1
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s1
)
)).
accept
()
==
false
);
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
1
)).
accept
()
==
false
);
CAPTURE
(
s2
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s2
)
)).
accept
()
==
false
);
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
2
)).
accept
()
==
false
);
CAPTURE
(
s3
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s3
)
)).
accept
()
==
false
);
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
3
)).
accept
()
==
false
);
CAPTURE
(
s4
)
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
td
::
string
(
s4
)
)).
accept
()
==
false
);
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
4
)).
accept
()
==
false
);
}
}
}
...
...
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