Skip to content

Commit b905e20

Browse files
committed
Replace assert with report_fatal_error
1 parent 12155be commit b905e20

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5319,7 +5319,9 @@ std::string
53195319
Converter::ConvertInitFragment(clang::Expr *expr,
53205320
const std::vector<clang::Expr *> &all_args) {
53215321
const auto *tgt_ir = RuleRegistry::GetExprRule(ctx_, expr);
5322-
assert(tgt_ir && tgt_ir->usesInit());
5322+
if (!tgt_ir || !tgt_ir->usesInit()) {
5323+
llvm::report_fatal_error("expression rule does not use Init");
5324+
}
53235325
auto type = RuleRegistry::GetInitType(expr);
53245326

53255327
Buffer buf(*this);

‎cpp2rust/converter/rules/registry.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ void addCxxRules(clang::ASTContext &ctx, const clang::NamespaceDecl *rules) {
160160
}
161161
for (auto decl : ns->decls()) {
162162
auto named = llvm::cast<clang::NamedDecl>(decl);
163-
assert(isRuleName(named->getName()) && "declaration is not a rule");
163+
if (!isRuleName(named->getName())) {
164+
llvm::report_fatal_error("declaration is not a rule");
165+
}
164166
addRule(ctx, dir.str(), named->getName().str(), named);
165167
}
166168
}
@@ -172,7 +174,9 @@ void addCRule(clang::ASTContext &ctx, const clang::NamedDecl *decl) {
172174
return;
173175
}
174176
auto [dir, name] = identifier.rsplit('_');
175-
assert(isRuleName(name) && "declaration is not a rule");
177+
if (!isRuleName(name)) {
178+
llvm::report_fatal_error("declaration is not a rule");
179+
}
176180
addRule(ctx, dir.str(), name.str(), decl);
177181
}
178182

@@ -197,8 +201,9 @@ ExprMatch findExpr(const clang::Expr *use) {
197201
use->dump(llvm::errs(), sema_->Context);
198202
it->second.decl->dump(llvm::errs());
199203
best.rule_decl->decl->dump(llvm::errs());
204+
llvm::report_fatal_error(
205+
"use matches several rules, none more specialized");
200206
}
201-
assert(better && "use matches several rules, none more specialized");
202207
if (better != it->second.decl) {
203208
continue;
204209
}
@@ -235,7 +240,10 @@ TypeRuleMatch findType(clang::QualType use) {
235240
if (match->depth == best.match.depth) {
236241
auto better = AstMatcher::MoreSpecializedType(*sema_, it->second.decl,
237242
best.rule_decl->decl);
238-
assert(better && "type matches several rules, none more specialized");
243+
if (!better) {
244+
llvm::report_fatal_error(
245+
"type matches several rules, none more specialized");
246+
}
239247
if (better != it->second.decl) {
240248
continue;
241249
}

0 commit comments

Comments
 (0)