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 for duplicate typedefs



Duplicate typedefs are legal, even in class scope.  We were
complaining spuriously.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-05-28  Mark Mitchell  <mark@codesourcery.com>

	* decl.c (add_binding): Don't complain about a redeclaration of a
	semantically identical typedef in a local scope.

Index: testsuite/g++.old-deja/g++.other/typedef7.C
===================================================================
RCS file: typedef7.C
diff -N typedef7.C
--- /dev/null	Sat Dec  5 20:30:03 1998
+++ typedef7.C	Fri May 28 02:25:42 1999
@@ -0,0 +1,17 @@
+// Build don't link:
+// Origin: Mark Mitchell <mark@codesourcery.com>
+
+typedef int I;
+typedef int I;
+
+struct A {
+  typedef int I;
+  typedef int I;
+};
+
+template <class T>
+struct S {
+  typedef int I;
+  typedef int I;
+};
+
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.365
diff -u -p -r1.365 decl.c
--- decl.c	1999/05/28 00:20:07	1.365
+++ decl.c	1999/05/28 09:25:51
@@ -1143,6 +1143,20 @@ add_binding (id, decl)
       BINDING_VALUE (binding) = decl;
       INHERITED_VALUE_BINDING_P (binding) = 0;
     }
+  else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL
+	   && TREE_CODE (decl) == TYPE_DECL
+	   && DECL_NAME (decl) == DECL_NAME (BINDING_VALUE (binding))
+	   && same_type_p (TREE_TYPE (decl),
+			   TREE_TYPE (BINDING_VALUE (binding))))
+    /* We have two typedef-names, both naming the same type to have
+       the same name.  This is OK because of:
+
+         [dcl.typedef]
+
+	 In a given scope, a typedef specifier can be used to redefine
+	 the name of any type declared in that scope to refer to the
+	 type to which it already refers.  */
+    ok = 0;
   else
     {
       cp_error ("declaration of `%#D'", decl);


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