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]

[C++ Patch] PR 4100 (friend specifier with class definition)


Hi,

I am trying to learn a little about the C++ parser in gcc and this
attempted bug fix is part of that process.  This bug allows a friend
decl-specifier to appear along with a class definition.  The fix
builds on a recent change to cp_parser_type_specifier that will now
return a code indicating whether a class type-specifier is a
declaration or a definition.  If a type specifier that defines a class
is seen and a friend specifier has also been seen then issue an error.

This change will cause an additional error message to appear in the
existing test case in testsuite/g++.old-deja/g++.pt/niklas01a.C .  The
patch also marks this new error.




Thanks,

Scott Brumbaugh




2003-08-14  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: gcc/cp/parser.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.100
diff -c -3 -p -r1.100 parser.c
*** gcc/cp/parser.c	12 Aug 2003 22:26:22 -0000	1.100
--- gcc/cp/parser.c	14 Aug 2003 05:43:35 -0000
*************** cp_parser_decl_specifier_seq (cp_parser*
*** 6426,6431 ****
--- 6426,6435 ----
        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: gcc/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
*** gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C	1 May 2003 02:02:55 -0000	1.4
--- gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C	14 Aug 2003 05:43:54 -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]