Skip to content

Commit 80da604

Browse files
committed
bitflags: Be explicit in binary operators and such.
This allows having explicit + default constructor without build issues.
1 parent 9855f90 commit 80da604

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/bindgen/ir/structure.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ impl Struct {
223223
out.open_brace();
224224
write!(
225225
out,
226-
"return {{static_cast<decltype(bits)>(this->bits {} {}.bits)}};",
226+
"return {} {{ static_cast<decltype(bits)>(this->bits {} {}.bits) }};",
227+
self.export_name(),
227228
operator, other
228229
);
229230
out.close_brace(false);
@@ -553,7 +554,7 @@ impl Source for Struct {
553554
self.export_name()
554555
);
555556
out.open_brace();
556-
write!(out, "return {{static_cast<decltype(bits)>(~bits)}};");
557+
write!(out, "return {} {{ static_cast<decltype(bits)>(~bits) }};", self.export_name());
557558
out.close_brace(false);
558559
self.emit_bitflags_binop(constexpr_prefix, '|', &other, out);
559560
self.emit_bitflags_binop(constexpr_prefix, '&', &other, out);

tests/expectations/associated_in_body.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ struct StyleAlignFlags {
1414
return !!bits;
1515
}
1616
constexpr StyleAlignFlags operator~() const {
17-
return {static_cast<decltype(bits)>(~bits)};
17+
return StyleAlignFlags { static_cast<decltype(bits)>(~bits) };
1818
}
1919
constexpr StyleAlignFlags operator|(const StyleAlignFlags& other) const {
20-
return {static_cast<decltype(bits)>(this->bits | other.bits)};
20+
return StyleAlignFlags { static_cast<decltype(bits)>(this->bits | other.bits) };
2121
}
2222
StyleAlignFlags& operator|=(const StyleAlignFlags& other) {
2323
*this = (*this | other);
2424
return *this;
2525
}
2626
constexpr StyleAlignFlags operator&(const StyleAlignFlags& other) const {
27-
return {static_cast<decltype(bits)>(this->bits & other.bits)};
27+
return StyleAlignFlags { static_cast<decltype(bits)>(this->bits & other.bits) };
2828
}
2929
StyleAlignFlags& operator&=(const StyleAlignFlags& other) {
3030
*this = (*this & other);
3131
return *this;
3232
}
3333
constexpr StyleAlignFlags operator^(const StyleAlignFlags& other) const {
34-
return {static_cast<decltype(bits)>(this->bits ^ other.bits)};
34+
return StyleAlignFlags { static_cast<decltype(bits)>(this->bits ^ other.bits) };
3535
}
3636
StyleAlignFlags& operator^=(const StyleAlignFlags& other) {
3737
*this = (*this ^ other);

tests/expectations/bitflags.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ struct AlignFlags {
1414
return !!bits;
1515
}
1616
constexpr AlignFlags operator~() const {
17-
return {static_cast<decltype(bits)>(~bits)};
17+
return AlignFlags { static_cast<decltype(bits)>(~bits) };
1818
}
1919
constexpr AlignFlags operator|(const AlignFlags& other) const {
20-
return {static_cast<decltype(bits)>(this->bits | other.bits)};
20+
return AlignFlags { static_cast<decltype(bits)>(this->bits | other.bits) };
2121
}
2222
AlignFlags& operator|=(const AlignFlags& other) {
2323
*this = (*this | other);
2424
return *this;
2525
}
2626
constexpr AlignFlags operator&(const AlignFlags& other) const {
27-
return {static_cast<decltype(bits)>(this->bits & other.bits)};
27+
return AlignFlags { static_cast<decltype(bits)>(this->bits & other.bits) };
2828
}
2929
AlignFlags& operator&=(const AlignFlags& other) {
3030
*this = (*this & other);
3131
return *this;
3232
}
3333
constexpr AlignFlags operator^(const AlignFlags& other) const {
34-
return {static_cast<decltype(bits)>(this->bits ^ other.bits)};
34+
return AlignFlags { static_cast<decltype(bits)>(this->bits ^ other.bits) };
3535
}
3636
AlignFlags& operator^=(const AlignFlags& other) {
3737
*this = (*this ^ other);
@@ -59,24 +59,24 @@ struct DebugFlags {
5959
return !!bits;
6060
}
6161
constexpr DebugFlags operator~() const {
62-
return {static_cast<decltype(bits)>(~bits)};
62+
return DebugFlags { static_cast<decltype(bits)>(~bits) };
6363
}
6464
constexpr DebugFlags operator|(const DebugFlags& other) const {
65-
return {static_cast<decltype(bits)>(this->bits | other.bits)};
65+
return DebugFlags { static_cast<decltype(bits)>(this->bits | other.bits) };
6666
}
6767
DebugFlags& operator|=(const DebugFlags& other) {
6868
*this = (*this | other);
6969
return *this;
7070
}
7171
constexpr DebugFlags operator&(const DebugFlags& other) const {
72-
return {static_cast<decltype(bits)>(this->bits & other.bits)};
72+
return DebugFlags { static_cast<decltype(bits)>(this->bits & other.bits) };
7373
}
7474
DebugFlags& operator&=(const DebugFlags& other) {
7575
*this = (*this & other);
7676
return *this;
7777
}
7878
constexpr DebugFlags operator^(const DebugFlags& other) const {
79-
return {static_cast<decltype(bits)>(this->bits ^ other.bits)};
79+
return DebugFlags { static_cast<decltype(bits)>(this->bits ^ other.bits) };
8080
}
8181
DebugFlags& operator^=(const DebugFlags& other) {
8282
*this = (*this ^ other);
@@ -93,24 +93,24 @@ struct LargeFlags {
9393
return !!bits;
9494
}
9595
constexpr LargeFlags operator~() const {
96-
return {static_cast<decltype(bits)>(~bits)};
96+
return LargeFlags { static_cast<decltype(bits)>(~bits) };
9797
}
9898
constexpr LargeFlags operator|(const LargeFlags& other) const {
99-
return {static_cast<decltype(bits)>(this->bits | other.bits)};
99+
return LargeFlags { static_cast<decltype(bits)>(this->bits | other.bits) };
100100
}
101101
LargeFlags& operator|=(const LargeFlags& other) {
102102
*this = (*this | other);
103103
return *this;
104104
}
105105
constexpr LargeFlags operator&(const LargeFlags& other) const {
106-
return {static_cast<decltype(bits)>(this->bits & other.bits)};
106+
return LargeFlags { static_cast<decltype(bits)>(this->bits & other.bits) };
107107
}
108108
LargeFlags& operator&=(const LargeFlags& other) {
109109
*this = (*this & other);
110110
return *this;
111111
}
112112
constexpr LargeFlags operator^(const LargeFlags& other) const {
113-
return {static_cast<decltype(bits)>(this->bits ^ other.bits)};
113+
return LargeFlags { static_cast<decltype(bits)>(this->bits ^ other.bits) };
114114
}
115115
LargeFlags& operator^=(const LargeFlags& other) {
116116
*this = (*this ^ other);

0 commit comments

Comments
 (0)