[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 12 21:33:46 PDT 2024


================
@@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() {
 
   auto *Eval = getEvaluatedStmt();
 
-  return cast_if_present<Expr>(
-      Eval->Value.isOffset()
-          ? Eval->Value.get(getASTContext().getExternalSource())
-          : Eval->Value.get(nullptr));
+  return cast<Expr>(Eval->Value.isOffset()
+                        ? Eval->Value.get(getASTContext().getExternalSource())
+                        : Eval->Value.get(nullptr));
----------------
mizvekov wrote:

Small nit: It seems this could move the conditional into the argument for `Eval->Value.get`.

https://github.com/llvm/llvm-project/pull/94515


More information about the cfe-commits mailing list