We shouldn't complain about friend temploids that we just haven't instantiated yet.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit a5742e86f3f8e1a2877b1dcf49403aaa8e7d0b86 Author: Jason Merrill <ja...@redhat.com> Date: Mon Dec 19 16:22:25 2016 -0500 PR c++/78749 - friend in anonymous namespace * decl.c (wrapup_globals_for_namespace): Don't complain about friend pseudo-template instantiations. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e83b542..2954160 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -926,6 +926,7 @@ wrapup_globals_for_namespace (tree name_space, void* data ATTRIBUTE_UNUSED) && DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl) && !DECL_ARTIFICIAL (decl) + && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl) && !TREE_NO_WARNING (decl)) { warning_at (DECL_SOURCE_LOCATION (decl), diff --git a/gcc/testsuite/g++.dg/warn/Wunused-function3.C b/gcc/testsuite/g++.dg/warn/Wunused-function3.C new file mode 100644 index 0000000..94c9025 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-function3.C @@ -0,0 +1,11 @@ +// { dg-options -Wunused-function } + +namespace +{ + template <class T> struct A + { + friend void f(A) { } + }; + + A<int> a; +}