From a8fc1497c0fa2e4b225c0fd685d91174b9fa6dd8 Mon Sep 17 00:00:00 2001 From: Johannes Pfau Date: Thu, 10 Jan 2013 19:16:53 +0100 Subject: [PATCH] Mark functions in nested template instance as non-public Templates can reference functions (via alias parameters), nested classes, nested structs or other templates referencing those. If a template uses such a reference which is only valid in a certain scope, it's functions can't be TREE_PUBLIC. (TREE_PUBLIC means the function can be called from outside the module) Some advanced test cases might still fail because of bugs in dmd fe's hasNestedArgs code: http://d.puremagic.com/issues/show_bug.cgi?id=9292 http://d.puremagic.com/issues/show_bug.cgi?id=3052 http://d.puremagic.com/issues/show_bug.cgi?id=8863 --- gcc/d/d-objfile.cc | 10 ++++++++-- 1 Datei geändert, 8 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-) diff --git a/gcc/d/d-objfile.cc b/gcc/d/d-objfile.cc index e3036c1..7e7adf1 100644 --- a/gcc/d/d-objfile.cc +++ b/gcc/d/d-objfile.cc @@ -270,6 +270,7 @@ ObjectFile::setupSymbolStorage (Dsymbol *dsym, tree decl_tree, bool force_static { bool has_module = false; bool is_template = false; + bool is_template_nested = false; Dsymbol *sym = dsym->toParent(); Module *ti_obj_file_mod; @@ -280,6 +281,7 @@ ObjectFile::setupSymbolStorage (Dsymbol *dsym, tree decl_tree, bool force_static { ti_obj_file_mod = ti->objFileModule; is_template = true; + is_template_nested = ti->isnested; break; } sym = sym->toParent(); @@ -315,8 +317,12 @@ ObjectFile::setupSymbolStorage (Dsymbol *dsym, tree decl_tree, bool force_static TREE_STATIC (decl_tree) = 0; } - // Do this by default, but allow private templates to override - if (!func_decl || !func_decl->isNested() || force_static_public) + //Members of templates which have parameters which are nested + //(e.g. nested function passed by alias) can't be public. + if(is_template_nested) + TREE_PUBLIC (decl_tree) = 0; + // Do this by default, but allow private templates to override + else if (!func_decl || !func_decl->isNested() || force_static_public) TREE_PUBLIC (decl_tree) = 1; if (D_DECL_ONE_ONLY (decl_tree)) -- 1.7.11.7