[gnu.g++.bug] friend bug and fix

jjc@UUNET.UU.NET (James Clark) (08/18/89)

g++ 1.35.1- incorrectly accepts this:

class A {
  int n;
 public:
  A();
  friend int foo(double);
  friend int foo(char);
};

int foo(A a)
{
  return a.n;
}

I think the fix for this is:

*** cplus-init.c.distrib        Fri Aug 18 13:01:19 1989
--- cplus-init.c        Fri Aug 18 13:02:00 1989
***************
*** 1703,1717 ****
  add_friend (type, decl)
       tree type, decl;
  {
    tree typedecl = TYPE_NAME (type);
    tree list = DECL_FRIENDLIST (typedecl);
    tree name = DECL_ORIGINAL_NAME (decl);
    tree ctype = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
!     ? TYPE_METHOD_BASETYPE (TREE_TYPE (decl)) : NULL_TREE;

    while (list)
      {
        if (name == TREE_PURPOSE (list))
        {
          tree friends = TREE_VALUE (list);
          while (friends)
--- 1703,1717 ----
  add_friend (type, decl)
       tree type, decl;
  {
    tree typedecl = TYPE_NAME (type);
    tree list = DECL_FRIENDLIST (typedecl);
    tree name = DECL_ORIGINAL_NAME (decl);
    tree ctype = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
!     ? TYPE_METHOD_BASETYPE (TREE_TYPE (decl)) : error_mark_node;

    while (list)
      {
        if (name == TREE_PURPOSE (list))
        {
          tree friends = TREE_VALUE (list);
          while (friends)

James Clark
jjc@jclark.uucp