From c9cbfca6f52f65d6914a33715d39ec9fa0619a18 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 24 Aug 2006 11:54:39 -0400 Subject: [PATCH] re PR c++/27714 (operator new as friend in template class rejected) PR c++/27714 * pt.c (push_template_decl_real): A friend template with class scope isn't primary. From-SVN: r116379 --- gcc/cp/ChangeLog | 8 +++++++- gcc/cp/pt.c | 8 +++++++- gcc/testsuite/g++.dg/template/friend46.C | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/friend46.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e2bc2dbb525..e1ad1bff31e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,4 +1,10 @@ -2006-08-11 Benjamin Smedberg +2006-08-23 Jason Merrill + + PR c++/27714 + * pt.c (push_template_decl_real): A friend template with class + scope isn't primary. + +2006-08-23 Benjamin Smedberg PR c++/28687 * rtti.c (build_dynamic_cast, build_dynamic_cast_1): diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4a58ef3cb6d..5843a50e57b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3022,7 +3022,13 @@ push_template_decl_real (tree decl, bool is_friend) DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); /* See if this is a primary template. */ - primary = template_parm_scope_p (); + if (is_friend && ctx) + /* A friend template that specifies a class context, i.e. + template friend void A::f(); + is not primary. */ + primary = 0; + else + primary = template_parm_scope_p (); if (primary) { diff --git a/gcc/testsuite/g++.dg/template/friend46.C b/gcc/testsuite/g++.dg/template/friend46.C new file mode 100644 index 00000000000..17dc0db943b --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend46.C @@ -0,0 +1,9 @@ +// PR c++/27714 + +template struct A +{ + static void* operator new(__SIZE_TYPE__); + template friend void* A::operator new(__SIZE_TYPE__); +}; + +A a; -- 2.30.2