diff --git a/src/delegatize.c b/src/delegatize.c index 8b7cae982186..ba1fc6102e69 100644 --- a/src/delegatize.c +++ b/src/delegatize.c @@ -19,6 +19,7 @@ #include "declaration.h" #include "aggregate.h" #include "scope.h" +#include "init.h" /******************************************** * Convert from expression to delegate that returns the expression, @@ -136,6 +137,30 @@ int lambdaCheckForNestedRef(Expression *e, void *param) break; } + case TOKdeclaration: + { DeclarationExp *de = (DeclarationExp *)e; + VarDeclaration *v = de->declaration->isVarDeclaration(); + if (v) + { + v->checkNestedReference(sc, 0); + + /* Some expressions cause the frontend to create a temporary. + * For example, structs with cpctors replace the original + * expression e with: + * __cpcttmp = __cpcttmp.cpctor(e); + * + * In this instance, we need to ensure that the original + * expression e does not have any nested references by + * checking the declaration initializer too. + */ + if (v->init && v->init->isExpInitializer()) + { Expression *ie = v->init->toExpression(); + ie->apply (&lambdaCheckForNestedRef, param); + } + } + break; + } + default: break; }