From 918d907f472f79a952dcf57e542183b3907f5a64 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 12 Jan 2001 09:13:16 +0000 Subject: [PATCH] cp: * friend.c (make_friend_class): Make sure a templated class is actually a template. testsuite: * g++.old-deja/g++.pt/friend47.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38939 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++ gcc/cp/friend.c | 48 +++++++++++++--------------- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.old-deja/g++.pt/friend47.C | 14 ++++++++ 4 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/friend47.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 995f49e..1297b2f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-01-12 Nathan Sidwell + + * friend.c (make_friend_class): Make sure a templated class is + actually a template. + 2001-01-11 Nathan Sidwell * decl2.c (get_guard): Set linkage from guarded decl. diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index df3281e..b817c7c 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -225,32 +225,30 @@ make_friend_class (type, friend_type) else is_template_friend = 0; - if (is_template_friend - && (TREE_CODE (friend_type) == TYPENAME_TYPE - || TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM)) + /* [temp.friend] + + A friend of a class or class template can be a function or + class template, a specialization of a function template or + class template, or an ordinary (nontemplate) function or + class. */ + if (!is_template_friend) + ;/* ok */ + else if (TREE_CODE (friend_type) == TYPENAME_TYPE) { - /* [temp.friend] - - A friend of a class or class template can be a function or - class template, a specialization of a function template or - class template, or an ordinary (nontemplate) function or - class. - - But, we're looking at something like: - - template friend typename S::X; - - or: - - template friend class T; - - which isn't any of these. */ - if (TREE_CODE (friend_type) == TYPENAME_TYPE) - cp_error ("typename type `%T' declared `friend'", - friend_type); - else - cp_error ("template parameter type `%T' declared `friend'", - friend_type); + /* template friend typename S::X; */ + cp_error ("typename type `%#T' declared `friend'", friend_type); + return; + } + else if (TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM) + { + /* template friend class T; */ + cp_error ("template parameter type `%T' declared `friend'", friend_type); + return; + } + else if (!CLASSTYPE_TEMPLATE_INFO (friend_type)) + { + /* template friend class A; where A is not a template */ + cp_error ("`%#T' is not a template", friend_type); return; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a37361..8c413ab 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-01-12 Nathan Sidwell + + * g++.old-deja/g++.pt/friend47.C: New test. + 2001-01-11 Nathan Sidwell * g++.old-deja/g++.pt/instantiate13.C: New test. diff --git a/gcc/testsuite/g++.old-deja/g++.pt/friend47.C b/gcc/testsuite/g++.old-deja/g++.pt/friend47.C new file mode 100644 index 0000000..37aa921 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/friend47.C @@ -0,0 +1,14 @@ +// Build don't link: + +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 7 Jan 2001 + +// Bug 1033. We ICE'd when trying to make a non template class a templated +// friend. + +class A {}; +class B { + template friend class A; // ERROR - not a template +}; + + -- 2.7.4