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]

C++ PATCH: Reject ill-formed declaration (fixes pr-97)



The patch below fixes pr-97 where we were ICEing on ill-formed
declaration like

	typedef union { };

We now reject the construct with a diagnostic.  However, we still fail
to reject

	enum { };

Bootstrapped and tested on i686-pc-linux-gnu.  No regression.
Approved by Mark.

-- Gaby
CodeSourcery, LLC                       http://www.codesourcery.com

2001-02-16  Gabriel Dos Reis <gdr@codesourcery.com>

cp/
	* decl.c (check_tag_decl): Make sure a typedef for an anonymous
	class-type introduces at least a type-name.

testsuite/
	* g++.old-deja/g++.other/decl9.C: New test.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.747.2.1
diff -p -r1.747.2.1 decl.c
*** decl.c	2001/02/14 06:46:12	1.747.2.1
--- decl.c	2001/02/16 22:27:20
*************** check_tag_decl (declspecs)
*** 6846,6851 ****
--- 6846,6852 ----
  {
    int found_type = 0;
    int saw_friend = 0;
+   int saw_typedef = 0;
    tree ob_modifier = NULL_TREE;
    register tree link;
    register tree t = NULL_TREE;
*************** check_tag_decl (declspecs)
*** 6877,6882 ****
--- 6878,6885 ----
  	      t = value;
  	    }
  	}
+       else if (value == ridpointers[(int) RID_TYPEDEF])
+         saw_typedef = 1;
        else if (value == ridpointers[(int) RID_FRIEND])
  	{
  	  if (current_class_type == NULL_TREE
*************** check_tag_decl (declspecs)
*** 6910,6915 ****
--- 6913,6939 ----
  	   && TYPE_NAME (t)
  	   && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
      {
+       /* 7/3 In a simple-declaration, the optional init-declarator-list
+          can be omitted only when declaring a class (clause 9) or
+          enumeration (7.2), that is, when the decl-specifier-seq contains
+          either a class-specifier, an elaborated-type-specifier with
+          a class-key (9.1), or an enum-specifier.  In these cases and
+          whenever a class-specifier or enum-specifier is present in the
+          decl-specifier-seq, the identifiers in these specifiers are among
+          the names being declared by the declaration (as class-name,
+          enum-names, or enumerators, depending on the syntax).  In such
+          cases, and except for the declaration of an unnamed bit-field (9.6),
+          the decl-specifier-seq shall introduce one or more names into the
+          program, or shall redeclare a name introduced by a previous
+          declaration.  [Example:
+              enum { };            // ill-formed
+              typedef class { };   // ill-formed
+          --end example]  */
+       if (saw_typedef)
+         {
+           error ("Missing type-name in typedef-declaration.");
+           return NULL_TREE;
+         }
        /* Anonymous unions are objects, so they can have specifiers.  */;
        SET_ANON_AGGR_TYPE_P (t);
  
Index: testsuite/g++.old-deja/g++.other/decl9.C
===================================================================
RCS file: decl9.C
diff -N decl9.C
*** /dev/null	Tue May  5 13:32:27 1998
--- decl9.C	Fri Feb 16 14:27:21 2001
***************
*** 0 ****
--- 1,9 ----
+ // Build don't link
+ // Origin: batali@cogsci.ucsd.edu
+ // Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
+ 
+ typedef struct { } S;           // OK
+ typedef struct { };             // ERROR - Missing type-name
+ 
+ typedef union { } U;            // OK
+ typedef union { };              // ERROR - Missing type-name


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