Skip to content

Commit 94ff2f6

Browse files
committed
Go with a more direct implementation; NFC
1 parent 3ee89ca commit 94ff2f6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,19 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
264264
// silence the "missing nonstring" diagnostic. If there's no entity,
265265
// check whether we're initializing an array of arrays; if so, walk the
266266
// parents to find an entity.
267-
auto FindCorrectEntity = [](const InitializedEntity &Entity) {
268-
const ValueDecl *Ret = nullptr;
269-
for (const InitializedEntity *E = &Entity; E; E = Entity.getParent()) {
270-
Ret = E->getDecl();
271-
if (Ret)
272-
break;
273-
if (!E->getType()->isArrayType())
274-
break;
267+
auto FindCorrectEntity =
268+
[](const InitializedEntity *Entity) -> const ValueDecl * {
269+
while (Entity) {
270+
if (const ValueDecl *VD = Entity->getDecl())
271+
return VD;
272+
if (!Entity->getType()->isArrayType())
273+
return nullptr;
274+
Entity = Entity->getParent();
275275
}
276-
return Ret;
276+
277+
return nullptr;
277278
};
278-
if (const ValueDecl *D = FindCorrectEntity(Entity);
279+
if (const ValueDecl *D = FindCorrectEntity(&Entity);
279280
!D || !D->hasAttr<NonStringAttr>())
280281
S.Diag(
281282
Str->getBeginLoc(),

0 commit comments

Comments
 (0)