diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index e8ed5fb749..d037ec57cd 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1822,11 +1822,12 @@ FuncDeclaration *getParentFunc(Dsymbol *sym) { return nullptr; } - // Static/non-extern(D) functions and function (not delegate) literals don't - // allow access to a parent context, even if they are nested. + // Static functions, non-extern(D) non-member functions and function (not + // delegate) literals don't allow access to a parent context, even if they are + // nested. if (FuncDeclaration *fd = sym->isFuncDeclaration()) { bool certainlyNewRoot = - fd->isStatic() || fd->linkage != LINKd || + fd->isStatic() || (!fd->isThis() && fd->linkage != LINKd) || (fd->isFuncLiteralDeclaration() && static_cast(fd)->tok == TOKfunction); if (certainlyNewRoot) { diff --git a/tests/compilable/gh2808.d b/tests/compilable/gh2808.d index 9c9580f208..4729da6175 100644 --- a/tests/compilable/gh2808.d +++ b/tests/compilable/gh2808.d @@ -1,6 +1,6 @@ // RUN: %ldc -c %s -void foo() +void gh2808() { extern(C) void DoubleArrayToAnyArray(void* arg0) { @@ -10,3 +10,14 @@ void foo() auto arg = () { return local; }(); DoubleArrayToAnyArray(null); } + +void gh3234() +{ + int i; + void nested() { ++i; } + + extern (C++) class Visitor + { + void visit() { nested(); } + } +}