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
ba046e4e
Unverified
Commit
ba046e4e
authored
Oct 14, 2021
by
Niels Lohmann
Committed by
GitHub
Oct 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to use get with explicit constructor (#3079)
*
⏪
remove "fix" that caused #3077
parent
0e694b40
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+1
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+1
-1
test/src/unit-regression2.cpp
test/src/unit-regression2.cpp
+34
-0
No files found.
include/nlohmann/json.hpp
View file @
ba046e4e
...
...
@@ -3069,7 +3069,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
ValueType
get_impl
(
detail
::
priority_tag
<
0
>
/*unused*/
)
const
noexcept
(
noexcept
(
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
ValueType
&>
())))
{
ValueType
ret
{}
;
auto
ret
=
ValueType
()
;
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
ret
);
return
ret
;
}
...
...
single_include/nlohmann/json.hpp
View file @
ba046e4e
...
...
@@ -20569,7 +20569,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
ValueType
get_impl
(
detail
::
priority_tag
<
0
>
/*unused*/
)
const
noexcept
(
noexcept
(
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
ValueType
&>
())))
{
ValueType
ret
{}
;
auto
ret
=
ValueType
()
;
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
ret
);
return
ret
;
}
...
...
test/src/unit-regression2.cpp
View file @
ba046e4e
...
...
@@ -201,6 +201,32 @@ template<class T>
class
my_allocator
:
public
std
::
allocator
<
T
>
{};
/////////////////////////////////////////////////////////////////////
// for #3077
/////////////////////////////////////////////////////////////////////
class
FooAlloc
{};
class
Foo
{
public:
explicit
Foo
(
const
FooAlloc
&
/* unused */
=
FooAlloc
())
{}
bool
value
=
false
;
};
class
FooBar
{
public:
Foo
foo
{};
};
inline
void
from_json
(
const
nlohmann
::
json
&
j
,
FooBar
&
fb
)
{
j
.
at
(
"value"
).
get_to
(
fb
.
foo
.
value
);
}
TEST_CASE
(
"regression tests 2"
)
{
SECTION
(
"issue #1001 - Fix memory leak during parser callback"
)
...
...
@@ -712,6 +738,14 @@ TEST_CASE("regression tests 2")
CHECK
(
j_path
==
text_path
);
}
#endif
SECTION
(
"issue #3077 - explicit constructor with default does not compile"
)
{
json
j
;
j
[
0
][
"value"
]
=
true
;
std
::
vector
<
FooBar
>
foo
;
j
.
get_to
(
foo
);
}
}
DOCTEST_CLANG_SUPPRESS_WARNING_POP
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