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: PATCH RFA: Clarify declares_class_or_enum in cp/parser.c


Jason Merrill <jason@redhat.com> writes:

> > I came up with this patch while looking at the patch in PR c++/4100.
> > The patch in that PR uses declares_class_or_enum in a way which did
> > not match the comment in the code.  Further investigation showed me
> > that the comment was wrong, and I am fairly certain that the patch is
> > correct.  Somebody with authority should approve that patch, and this
> > one too.
> 
> Yes, that patch looks good.  Would you mind checking it in along with
> yours?

This is what I checked in.

Ian


cp/ChangeLog:

2004-01-12  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.

testsuite/ChangeLog:

2004-01-12  Ian Lance Taylor  <ian@wasabisystems.com>

	PR c++/4100
	* g++.dg/parse/friend4.C: New test.

2004-01-12  Scott Brumbaugh  <scottb.lists@verizon.net>

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


Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.150
diff -p -u -r1.150 parser.c
--- cp/parser.c	12 Jan 2004 15:25:16 -0000	1.150
+++ cp/parser.c	12 Jan 2004 15:59:23 -0000
@@ -6726,6 +6726,10 @@ cp_parser_decl_specifier_seq (cp_parser*
       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++.dg/parse/friend4.C
===================================================================
RCS file: testsuite/g++.dg/parse/friend4.C
diff -N testsuite/g++.dg/parse/friend4.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/parse/friend4.C	12 Jan 2004 15:59:26 -0000
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+// PR c++/4100
+// You can't use friend when defining a class.
+
+class A {
+  friend class B { };	// { dg-error "friend" }
+};
Index: testsuite/g++.old-deja/g++.pt/niklas01a.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C,v
retrieving revision 1.4
diff -p -u -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	12 Jan 2004 15:59:26 -0000
@@ -3,6 +3,6 @@
 struct A { // { dg-error "" } forward declaration
   friend struct B : A {		// { dg-error "" } 
     int x;
-  };
+  };	// { dg-error "" } class definition cannot be a friend
   int y;
 };


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