Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
f1320274
Commit
f1320274
authored
Mar 29, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix implicit conversions of Maybe in multi-step conversion cases.
parent
938d1e03
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
common-test.c++
c++/src/kj/common-test.c++
+25
-0
common.h
c++/src/kj/common.h
+2
-2
No files found.
c++/src/kj/common-test.c++
View file @
f1320274
...
...
@@ -37,6 +37,14 @@ KJ_TEST("kj::size() on native arrays") {
KJ_EXPECT
(
expected
==
4u
);
}
struct
ImplicitToInt
{
int
i
;
operator
int
()
const
{
return
i
;
}
};
TEST
(
Common
,
Maybe
)
{
{
Maybe
<
int
>
m
=
123
;
...
...
@@ -166,6 +174,23 @@ TEST(Common, Maybe) {
EXPECT_EQ
(
0
,
*
v
);
// avoid unused warning
}
}
{
// Test a case where an implicit conversion didn't used to happen correctly.
Maybe
<
ImplicitToInt
>
m
(
ImplicitToInt
{
123
});
Maybe
<
uint
>
m2
(
m
);
Maybe
<
uint
>
m3
(
kj
::
mv
(
m
));
KJ_IF_MAYBE
(
v
,
m2
)
{
EXPECT_EQ
(
123
,
*
v
);
}
else
{
ADD_FAILURE
();
}
KJ_IF_MAYBE
(
v
,
m3
)
{
EXPECT_EQ
(
123
,
*
v
);
}
else
{
ADD_FAILURE
();
}
}
}
TEST
(
Common
,
MaybeConstness
)
{
...
...
c++/src/kj/common.h
View file @
f1320274
...
...
@@ -1031,13 +1031,13 @@ public:
template
<
typename
U
>
Maybe
(
Maybe
<
U
>&&
other
)
noexcept
(
noexcept
(
T
(
instance
<
U
&&>
())))
{
KJ_IF_MAYBE
(
val
,
kj
::
mv
(
other
))
{
ptr
=
*
val
;
ptr
.
emplace
(
kj
::
mv
(
*
val
))
;
}
}
template
<
typename
U
>
Maybe
(
const
Maybe
<
U
>&
other
)
{
KJ_IF_MAYBE
(
val
,
other
)
{
ptr
=
*
val
;
ptr
.
emplace
(
*
val
)
;
}
}
...
...
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