Skip to content

Commit 22a8fa0

Browse files
committed
Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit
VarDecl::isNull() doesn't tell whether the VarDecl has an initializer as methods like ensureEvaluatedStmt can create an EvaluatedStmt even when there isn't an initializer. Revert e1c3e16 as the change isn't needed anymore with this change. See the discussion in llvm#93749.
1 parent 461dcd4 commit 22a8fa0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/AST/Decl.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,9 @@ bool VarDecl::hasInit() const {
23902390
if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg())
23912391
return false;
23922392

2393+
if (auto *Eval = getEvaluatedStmt())
2394+
return Eval->Value.isValid();
2395+
23932396
return !Init.isNull();
23942397
}
23952398

@@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() {
24022405

24032406
auto *Eval = getEvaluatedStmt();
24042407

2405-
return cast_if_present<Expr>(
2406-
Eval->Value.isOffset()
2407-
? Eval->Value.get(getASTContext().getExternalSource())
2408-
: Eval->Value.get(nullptr));
2408+
return cast<Expr>(Eval->Value.isOffset()
2409+
? Eval->Value.get(getASTContext().getExternalSource())
2410+
: Eval->Value.get(nullptr));
24092411
}
24102412

24112413
Stmt **VarDecl::getInitAddress() {

0 commit comments

Comments
 (0)