This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Friend class and DR 180 (take 2)


Jason Merrill wrote:

On Wed, 27 Nov 2002 20:54:00 +0700, Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> wrote:


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.

I think the other TYPE_IDENTIFIER is also redundant.  With that change,
this is OK.

I'd disagree here. 'type' is a TYPENAME_TYPE node. Calling pedwarn with
simply 'type' would output entire type, i.e. 'typename A::B'. But we want
to instruct user the correct syntax with the above 'typename' keyword
replaced by 'class'.

I think the suggested TYPE_IDENTIFIER should be replaced by
TYPENAME_TYPE_FULLNAME instead. The TYPE_IDENTIFIER does not work correctly
with the error code like 'friend typename T::C<int>;'. The diagnostic suggests
user with 'friend class T::C' but should output 'friend class T::C<int>'
instead. The corrected patch appears below. OK for main trunk?

--Kriang

2002-11-28 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>

DR 180
* decl.c (grokdeclarator): Require class-key for all friend class.
Output the correct type and context in the error message.

2002-11-28 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 Thu Nov 28 19:02:33 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::%D'",
! TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (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
};





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]