diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1f19dadafa44e8..fc04f877b22681 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2390,6 +2390,9 @@ bool VarDecl::hasInit() const { if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg()) return false; + if (auto *Eval = getEvaluatedStmt()) + return Eval->Value.isValid(); + return !Init.isNull(); } @@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() { auto *Eval = getEvaluatedStmt(); - return cast_if_present( - Eval->Value.isOffset() - ? Eval->Value.get(getASTContext().getExternalSource()) - : Eval->Value.get(nullptr)); + return cast(Eval->Value.isOffset() + ? Eval->Value.get(getASTContext().getExternalSource()) + : Eval->Value.get(nullptr)); } Stmt **VarDecl::getInitAddress() {