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] PR 4100 (friend specifier with class definition)


Hi,

This is an update to the earlier version of the patch.  I have changed
the comparison of the bit flag declares_class_or_enum to bitwise-and.
Tested with make bootstrap and make check-g++ on i686-pc-linux-gnu.


Thanks,


Scott Brumbaugh



2003-09-22  Scott Brumbaugh  <scottb.lists@verizon.net>

	PR C++/4100

	* parser.c (cp_parser_decl_specifier_seq): Add check for a
	friend decl-specifier occurring along with a class definition.

	* g++.old-deja/g++.pt/niklas01a.C: Mark an error where a class
	definition is called a friend.


Index: cp/parser.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.111
diff -c -3 -p -r1.111 parser.c
*** cp/parser.c	20 Sep 2003 15:59:36 -0000	1.111
--- cp/parser.c	22 Sep 2003 03:36:44 -0000
*************** cp_parser_decl_specifier_seq (cp_parser*
*** 6448,6453 ****
--- 6448,6457 ----
        flags |= CP_PARSER_FLAGS_OPTIONAL;
      }
  
+   /* Don't allow a friend specifier with a class definition. */
+   if (friend_p && *declares_class_or_enum & 2)
+     error("class definition may not be declared a friend");
+ 
    /* We have built up the DECL_SPECS in reverse order.  Return them in
       the correct order.  */
    return nreverse (decl_specs);
Index: testsuite/g++.old-deja/g++.pt/niklas01a.C
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C,v
retrieving revision 1.4
diff -c -3 -p -r1.4 niklas01a.C
*** testsuite/g++.old-deja/g++.pt/niklas01a.C	1 May 2003 02:02:55 -0000	1.4
--- testsuite/g++.old-deja/g++.pt/niklas01a.C	22 Sep 2003 03:37:03 -0000
***************
*** 3,8 ****
  struct A { // { dg-error "" } forward declaration
    friend struct B : A {		// { dg-error "" } 
      int x;
!   };
    int y;
  };
--- 3,8 ----
  struct A { // { dg-error "" } forward declaration
    friend struct B : A {		// { dg-error "" } 
      int x;
!   };  // { dg-error "" } class definition cannot be a friend
    int y;
  };



// { dg-do compile }

// PR 4100 friend specifier allowed with class definition.

struct S
{
	friend class C {}; // { dg-error "" }
};


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