diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2001-01-12 09:13:16 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2001-01-12 09:13:16 +0000 |
commit | a86416613524dc3f345afef4d66c19e7e35380df (patch) | |
tree | e5057553b77437c2e9d30b11db8c1abefd968f62 /gcc | |
parent | 47d4f116352ea38ee0e0c156d9bd06eddb888fee (diff) | |
download | gcc-a86416613524dc3f345afef4d66c19e7e35380df.zip gcc-a86416613524dc3f345afef4d66c19e7e35380df.tar.gz gcc-a86416613524dc3f345afef4d66c19e7e35380df.tar.bz2 |
friend.c (make_friend_class): Make sure a templated class is actually a template.
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.
From-SVN: r38939
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/friend.c | 48 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.pt/friend47.C | 14 |
4 files changed, 46 insertions, 25 deletions
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 <nathan@codesourcery.com> + + * friend.c (make_friend_class): Make sure a templated class is + actually a template. + 2001-01-11 Nathan Sidwell <nathan@codesourcery.com> * 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 <class T> friend typename S<T>::X; - - or: - - template <class T> 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 <class T> friend typename S<T>::X; */ + cp_error ("typename type `%#T' declared `friend'", friend_type); + return; + } + else if (TREE_CODE (friend_type) == TEMPLATE_TYPE_PARM) + { + /* template <class T> friend class T; */ + cp_error ("template parameter type `%T' declared `friend'", friend_type); + return; + } + else if (!CLASSTYPE_TEMPLATE_INFO (friend_type)) + { + /* template <class T> 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 <nathan@codesourcery.com> + + * g++.old-deja/g++.pt/friend47.C: New test. + 2001-01-11 Nathan Sidwell <nathan@codesourcery.com> * 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 <nathan@codesourcery.com> + +// Bug 1033. We ICE'd when trying to make a non template class a templated +// friend. + +class A {}; +class B { + template<class T> friend class A; // ERROR - not a template +}; + + |