Skip to content

Commit 65ea32a

Browse files
committed
Fix default for enum with bool underlying type
1 parent 2bb3063 commit 65ea32a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,7 @@ std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) {
42854285
if (qual_type->isEnumeralType()) {
42864286
auto enum_decl = qual_type->castAs<clang::EnumType>()->getDecl();
42874287
if (enum_decl->enumerators().empty()) {
4288-
return std::string(1, token::kZero);
4288+
return GetDefaultAsString(enum_decl->getIntegerType());
42894289
}
42904290
return EnumeratorName(*enum_decl->enumerator_begin());
42914291
}

‎tests/unit/enum_underlying_type.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ enum Sized : uint16_t { SIZED_A = 1, SIZED_B = 0xFFFF };
1313

1414
enum class Scoped : int8_t { NEG = -2, POS = 2 };
1515

16+
enum Empty : bool {};
17+
18+
struct HoldsEmpty {
19+
Empty e{};
20+
};
21+
1622
int main() {
1723
Flag flag = FLAG_ON;
1824
assert(flag);
@@ -45,5 +51,10 @@ int main() {
4551
Scoped sc = Scoped::NEG;
4652
assert(static_cast<int>(sc) == -2);
4753
assert(static_cast<int8_t>(Scoped::POS) == 2);
54+
55+
HoldsEmpty he;
56+
assert(!he.e);
57+
Empty ev{};
58+
assert(ev == he.e);
4859
return 0;
4960
}

0 commit comments

Comments
 (0)