commit 668c1f7aebfcc94faee89fd36e2a2258095761c3 Author: Jason Merrill Date: Thu Dec 24 16:26:59 2009 -0500 PR c++/38392 * pt.c (tsubst_friend_function): Instatiate a friend that has already been used. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 85ad539..958099c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7141,11 +7141,18 @@ tsubst_friend_function (tree decl, tree args) DECL_TEMPLATE_INFO (old_decl) = new_friend_template_info; if (TREE_CODE (old_decl) != TEMPLATE_DECL) - /* We should have called reregister_specialization in - duplicate_decls. */ - gcc_assert (retrieve_specialization (new_template, - new_args, 0) - == old_decl); + { + /* We should have called reregister_specialization in + duplicate_decls. */ + gcc_assert (retrieve_specialization (new_template, + new_args, 0) + == old_decl); + + /* Instantiate it if the global has already been used. */ + if (DECL_ODR_USED (old_decl)) + instantiate_decl (old_decl, /*defer_ok=*/true, + /*expl_inst_class_mem_p=*/false); + } else { tree t; diff --git a/gcc/testsuite/g++.dg/template/friend51.C b/gcc/testsuite/g++.dg/template/friend51.C new file mode 100644 index 0000000..3e0540e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend51.C @@ -0,0 +1,16 @@ +// PR c++/38392 + +void Function(); + +int main() +{ + Function(); +} + +template +struct Test +{ + friend void Function() { } +}; + +template class Test;