Remove variant checks when they precede a `std::get<>(Variant)` call.
If the wrong variant is active, `std::get<>` will throw an exception, and terminate the process because exceptions are disabled. If we don't want to rely on exceptions terminating the process, then IMO we should use a function that is like std::get but crashes, as so:
```cc
template <size_t i, typename T>
auto GetOrDie(T&& variant) noexcept -> decltype(std::get<i>(variant)) {
return std::get<i>(std::forward(variant));
}
```
The `assert(!IsError())` calls don't have as much information about what went wrong as the exception might, and are easy to forget. When it's an `assert`, it only ever does things in debug mode anyway.
PiperOrigin-RevId: 498611220
diff --git a/lifetime_analysis/lifetime_lattice.cc b/lifetime_analysis/lifetime_lattice.cc
index 0dce6e5..d3653b5 100644
--- a/lifetime_analysis/lifetime_lattice.cc
+++ b/lifetime_analysis/lifetime_lattice.cc
@@ -25,31 +25,22 @@
}
PointsToMap& LifetimeLattice::PointsTo() {
- assert(!IsError());
return std::get<0>(var_).first;
}
const PointsToMap& LifetimeLattice::PointsTo() const {
- assert(!IsError());
return std::get<0>(var_).first;
}
LifetimeConstraints& LifetimeLattice::Constraints() {
- assert(!IsError());
return std::get<0>(var_).second;
}
const LifetimeConstraints& LifetimeLattice::Constraints() const {
- assert(!IsError());
return std::get<0>(var_).second;
}
llvm::StringRef LifetimeLattice::Error() const {
- assert(IsError());
- if (!IsError()) {
- llvm::report_fatal_error(
- "Trying to access error on non-error LifetimeLattice");
- }
return std::get<std::string>(var_);
}