Skip to content

Commit f3698d6

Browse files
committed
Handle anonymous structs inside records
1 parent d9180fc commit f3698d6

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,10 +2837,6 @@ std::string Converter::GetRecordName(const clang::NamedDecl *decl) const {
28372837
if (auto it = inner_structs_.find(ID); it != inner_structs_.end()) {
28382838
return it->second;
28392839
}
2840-
if (auto *record = clang::dyn_cast<clang::RecordDecl>(decl);
2841-
record && !record->getIdentifier()) {
2842-
return ID;
2843-
}
28442840
return std::regex_replace(Mapper::ToString(decl), std::regex("::"), "_");
28452841
}
28462842

cpp2rust/converter/mapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ std::string ToString(clang::QualType qual_type) {
735735
return normalizeTranslationRule(type);
736736
}
737737

738+
static std::string synthesizeAnonRecordName(const clang::RecordDecl *record) {
739+
std::string parent_name;
740+
if (auto *parent =
741+
clang::dyn_cast<clang::RecordDecl>(record->getDeclContext())) {
742+
parent_name =
743+
parent->getIdentifier() ? parent->getIdentifier()->getName().str();
744+
: synthesizeAnonRecordName(parent);
745+
}
746+
return std::format("{}_anon_{}", parent_name, GetAnonIndex(record));
747+
}
748+
738749
std::string ToString(const clang::NamedDecl *decl) {
739750
if (auto *record = clang::dyn_cast<clang::RecordDecl>(decl);
740751
record && !record->getIdentifier()) {

0 commit comments

Comments
 (0)