Wrap tag into anonymous struct in C++

Fixes #122
This commit is contained in:
Ingvar Stepanyan
2018-01-30 21:35:42 +00:00
committed by Ryan Hunt
parent 0ebcf99d31
commit f9b8512dc2
3 changed files with 20 additions and 2 deletions
+14
View File
@@ -357,7 +357,21 @@ impl Source for Enum {
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);
if wrap_tag {
out.close_brace(true);
}
out.new_line();
if separate_tag {
+3 -1
View File
@@ -34,7 +34,9 @@ union DisplayItem {
Rect bounds;
};
Tag tag;
struct {
Tag tag;
};
Fill_Body fill;
Image_Body image;
};
+3 -1
View File
@@ -56,7 +56,9 @@ union F {
int16_t y;
};
Tag tag;
struct {
Tag tag;
};
Foo_Body foo;
Bar_Body bar;
};