Commit f9b8512d authored by Ingvar Stepanyan's avatar Ingvar Stepanyan Committed by Ryan Hunt

Wrap tag into anonymous struct in C++

Fixes #122
parent 0ebcf99d
...@@ -357,7 +357,21 @@ impl Source for Enum { ...@@ -357,7 +357,21 @@ impl Source for Enum {
out.open_brace(); out.open_brace();
} }
// C++ allows accessing only common initial sequence of union
// branches so we need to wrap tag into an anonymous struct
let wrap_tag = config.language == Language::Cxx && !separate_tag;
if wrap_tag {
out.write("struct");
out.open_brace();
}
write!(out, "{} tag;", enum_name); write!(out, "{} tag;", enum_name);
if wrap_tag {
out.close_brace(true);
}
out.new_line(); out.new_line();
if separate_tag { if separate_tag {
......
...@@ -34,7 +34,9 @@ union DisplayItem { ...@@ -34,7 +34,9 @@ union DisplayItem {
Rect bounds; Rect bounds;
}; };
Tag tag; struct {
Tag tag;
};
Fill_Body fill; Fill_Body fill;
Image_Body image; Image_Body image;
}; };
......
...@@ -56,7 +56,9 @@ union F { ...@@ -56,7 +56,9 @@ union F {
int16_t y; int16_t y;
}; };
Tag tag; struct {
Tag tag;
};
Foo_Body foo; Foo_Body foo;
Bar_Body bar; Bar_Body bar;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment