This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Friend class and DR 180 (take 2)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 27 Nov 2002 20:54:00 +0700
- Subject: [C++ PATCH] Friend class and DR 180 (take 2)
- Reply-to: lerdsuwa at users dot sourceforge dot net
Hi
This is a revised version of the friend patch submitted yesterday.
The diagnostic character string is cleaned up and the redundant
TYPE_IDENTIFIER macro is removed.
Bootstrapped and tested on i686-pc-linux-gnu with no regressions.
OK to commit to main trunk?
--Kriang
2002-11-27 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
DR 180
* decl.c (grokdeclarator): Require class-key for all friend class.
Output the correct context in the error message.
2002-11-27 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
DR 180
* g++.old-deja/g++.pt/crash32.C: Expect error.
diff -cprN gcc-main-save2/gcc/cp/decl.c gcc-main-new2/gcc/cp/decl.c
*** gcc-main-save2/gcc/cp/decl.c Tue Nov 26 19:46:40 2002
--- gcc-main-new2/gcc/cp/decl.c Tue Nov 26 19:42:47 2002
*************** grokdeclarator (declarator, declspecs, d
*** 11635,11656 ****
inlinep = 0;
}
! /* Until core issue 180 is resolved, allow 'friend typename A::B'.
! But don't allow implicit typenames except with a class-key. */
! if (!current_aggr && (TREE_CODE (type) != TYPENAME_TYPE
! || IMPLICIT_TYPENAME_P (type)))
{
if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
! pedwarn ("template parameters cannot be friends");
else if (TREE_CODE (type) == TYPENAME_TYPE)
! pedwarn ("\
! friend declaration requires class-key, i.e. `friend class %T::%T'",
! constructor_name (current_class_type),
! TYPE_IDENTIFIER (type));
else
! pedwarn ("\
! friend declaration requires class-key, i.e. `friend %#T'",
! type);
}
/* Only try to do this stuff if we didn't already give up. */
--- 11635,11653 ----
inlinep = 0;
}
! if (!current_aggr)
{
+ /* Don't allow friend declaration without a class-key. */
if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
! pedwarn ("template parameters cannot be friends");
else if (TREE_CODE (type) == TYPENAME_TYPE)
! pedwarn ("friend declaration requires class-key, "
! "i.e. `friend class %T::%T'",
! TYPE_CONTEXT (type), TYPE_IDENTIFIER (type));
else
! pedwarn ("friend declaration requires class-key, "
! "i.e. `friend %#T'",
! type);
}
/* Only try to do this stuff if we didn't already give up. */
diff -cprN gcc-main-save2/gcc/testsuite/g++.old-deja/g++.pt/crash32.C gcc-main-new2/gcc/testsuite/g++.old-deja/g++.pt/crash32.C
*** gcc-main-save2/gcc/testsuite/g++.old-deja/g++.pt/crash32.C Tue Nov 26 19:45:46 2002
--- gcc-main-new2/gcc/testsuite/g++.old-deja/g++.pt/crash32.C Tue Nov 26 14:01:57 2002
*************** template <class T> struct A
*** 8,13 ****
template<class T> struct C
{
! friend typename A<T>::B;
};
--- 8,13 ----
template<class T> struct C
{
! friend typename A<T>::B; // ERROR - struct is required
};