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
ca469daa
Unverified
Commit
ca469daa
authored
Dec 22, 2017
by
Kenton Varda
Committed by
GitHub
Dec 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #607 from capnproto/fix-maybe-one-of
KJ_SWITCH_ONEOF should parenthesize its argument
parents
ac10f36b
d7ddd58d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
one-of-test.c++
c++/src/kj/one-of-test.c++
+19
-0
one-of.h
c++/src/kj/one-of.h
+2
-2
No files found.
c++/src/kj/one-of-test.c++
View file @
ca469daa
...
@@ -151,4 +151,23 @@ TEST(OneOf, Switch) {
...
@@ -151,4 +151,23 @@ TEST(OneOf, Switch) {
}
}
}
}
TEST
(
OneOf
,
Maybe
)
{
Maybe
<
OneOf
<
int
,
float
>>
var
;
var
=
OneOf
<
int
,
float
>
(
123
);
KJ_IF_MAYBE
(
v
,
var
)
{
// At one time this failed to compile. Note that a Maybe<OneOf<...>> isn't necessarily great
// style -- you might be better off with an explicit OneOf<Empty, ...>. Nevertheless, it should
// compile.
KJ_SWITCH_ONEOF
(
*
v
)
{
KJ_CASE_ONEOF
(
i
,
int
)
{
KJ_EXPECT
(
i
==
123
);
}
KJ_CASE_ONEOF
(
n
,
float
)
{
KJ_FAIL_ASSERT
(
"expected int, got float"
,
n
);
}
}
}
}
}
// namespace kj
}
// namespace kj
c++/src/kj/one-of.h
View file @
ca469daa
...
@@ -238,11 +238,11 @@ void OneOf<Variants...>::allHandled() {
...
@@ -238,11 +238,11 @@ void OneOf<Variants...>::allHandled() {
#if __cplusplus > 201402L
#if __cplusplus > 201402L
#define KJ_SWITCH_ONEOF(value) \
#define KJ_SWITCH_ONEOF(value) \
switch (auto _kj_switch_subject =
value
._switchSubject(); _kj_switch_subject->which())
switch (auto _kj_switch_subject =
(value)
._switchSubject(); _kj_switch_subject->which())
#else
#else
#define KJ_SWITCH_ONEOF(value) \
#define KJ_SWITCH_ONEOF(value) \
/* Without C++17, we can only support one switch per containing block. Deal with it. */
\
/* Without C++17, we can only support one switch per containing block. Deal with it. */
\
auto _kj_switch_subject =
value
._switchSubject(); \
auto _kj_switch_subject =
(value)
._switchSubject(); \
switch (_kj_switch_subject->which())
switch (_kj_switch_subject->which())
#endif
#endif
#define KJ_CASE_ONEOF(name, ...) \
#define KJ_CASE_ONEOF(name, ...) \
...
...
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