re PR c++/17473 (typedef redefinition in struct is accepted)
authorMark Mitchell <mark@codesourcery.com>
Wed, 24 Nov 2004 23:18:56 +0000 (23:18 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 24 Nov 2004 23:18:56 +0000 (23:18 +0000)
PR c++/17473
* name-lookup.c (supplement_binding): Do not allow typedefs to be
redefined in class scope.

PR c++/18285
* parser.c (cp_parser_set_decl_type_spec): Do not try to allow
redefinitions of builtin types other that "bool" or "wchar_t".

PR c++/17473
* g++.dg/tc1/dr56.C: Remove.
* g++.dg/template/typedef1.C: Add dg-error markers.
* g++.old-deja/g++.other/typedef7.C: Likewise.

PR c++/18285
* g++.dg/parse/typedef7.C: New test.

From-SVN: r91254

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/typedef7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tc1/dr56.C [deleted file]
gcc/testsuite/g++.dg/template/typedef1.C
gcc/testsuite/g++.old-deja/g++.other/typedef7.C

index 95e2ed4..ecc122e 100644 (file)
@@ -1,3 +1,13 @@
+2004-11-24  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/17473
+       * name-lookup.c (supplement_binding): Do not allow typedefs to be
+       redefined in class scope.
+
+       PR c++/18285
+       * parser.c (cp_parser_set_decl_type_spec): Do not try to allow
+       redefinitions of builtin types other that "bool" or "wchar_t".
+
 2004-11-24  Steven Bosscher  <stevenb@suse.de>
 
        * decl.c (cxx_init_decl_processing): Don't clear
index 0abe1ec..29b93ff 100644 (file)
@@ -531,19 +531,24 @@ supplement_binding (cxx_binding *binding, tree decl)
   else if (TREE_CODE (bval) == TYPE_DECL
           && TREE_CODE (decl) == TYPE_DECL
           && DECL_NAME (decl) == DECL_NAME (bval)
+          && binding->scope->kind != sk_class
           && (same_type_p (TREE_TYPE (decl), TREE_TYPE (bval))
               /* If either type involves template parameters, we must
                  wait until instantiation.  */
               || uses_template_parms (TREE_TYPE (decl))
               || uses_template_parms (TREE_TYPE (bval))))
     /* We have two typedef-names, both naming the same type to have
-       the same name.  This is OK because of:
+       the same name.  In general, 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.  */
+        type to which it already refers.  
+
+       However, in class scopes, this rule does not apply due to the
+       stricter language in [class.mem] prohibiting redeclarations of
+       members.  */
     ok = false;
   /* There can be two block-scope declarations of the same variable,
      so long as they are `extern' declarations.  However, there cannot
index ccd8a95..1a97868 100644 (file)
@@ -15343,12 +15343,14 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
 {
   decl_specs->any_specifiers_p = true;
 
-  /* If the user tries to redeclare a built-in type (with, for example,
-     in "typedef int wchar_t;") we remember that this is what
+  /* If the user tries to redeclare bool or wchar_t (with, for
+     example, in "typedef int wchar_t;") we remember that this is what
      happened.  In system headers, we ignore these declarations so
      that G++ can work with system headers that are not C++-safe.  */
   if (decl_specs->specs[(int) ds_typedef]
       && !user_defined_p
+      && (type_spec == boolean_type_node
+         || type_spec == wchar_type_node)
       && (decl_specs->type
          || decl_specs->specs[(int) ds_long]
          || decl_specs->specs[(int) ds_short]
index 25f2f13..19579e9 100644 (file)
@@ -1,3 +1,13 @@
+2004-11-24  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/17473
+       * g++.dg/tc1/dr56.C: Remove.
+       * g++.dg/template/typedef1.C: Add dg-error markers.
+       * g++.old-deja/g++.other/typedef7.C: Likewise.
+
+       PR c++/18285
+       * g++.dg/parse/typedef7.C: New test.
+
 2004-11-24  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.c-torture/execute/20041124-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/parse/typedef7.C b/gcc/testsuite/g++.dg/parse/typedef7.C
new file mode 100644 (file)
index 0000000..126fb7e
--- /dev/null
@@ -0,0 +1,2 @@
+// PR c++/18285
+typedef void int char void double X; // { dg-error "" } 
diff --git a/gcc/testsuite/g++.dg/tc1/dr56.C b/gcc/testsuite/g++.dg/tc1/dr56.C
deleted file mode 100644 (file)
index a5caea8..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// { dg-do compile }
-// Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
-// DR56: Redeclaring typedefs within classes 
-
-class X { 
-  typedef int I; 
-  typedef int I;  // { dg-error "" "Cannot redeclare a typedef in a class scope" { xfail *-*-* } }
-};
-
-// In non-class scope, they are allowed.
-typedef int A;
-typedef int A;
index 0325757..75b00e0 100644 (file)
@@ -12,10 +12,10 @@ template <typename T> struct A
 
 template <typename T> struct B
 {
-  typedef int xxx;
-  typedef T xxx;
-  typedef typename A<T>::type xxx;
-  typedef A<int>::type xxx;
+  typedef int xxx; // { dg-error "" }
+  typedef T xxx; // { dg-error "" }
+  typedef typename A<T>::type xxx; // { dg-error "" }
+  typedef A<int>::type xxx; // { dg-error "" }
 };
 
 B<int> good;
index f49ae47..42cf4f1 100644 (file)
@@ -4,14 +4,17 @@
 typedef int I;
 typedef int I;
 
+// DR56 makes clear that duplicate typedefs in class scopes are
+// invalid.
+
 struct A {
-  typedef int I;
-  typedef int I;
+  typedef int I; // { dg-error "" }
+  typedef int I; // { dg-error "" }
 };
 
 template <class T>
 struct S {
-  typedef int I;
-  typedef int I;
+  typedef int I;  // { dg-error "" }
+  typedef int I;  // { dg-error "" }
 };