OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 2 Mar 2002 19:51:57 +0000 (19:51 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 2 Mar 2002 19:51:57 +0000 (19:51 +0000)
        PR c++/775
        * decl.c (lookup_tag): Only reject enum/class mismatch, not
        class/union mismatch.
        * parse.y (check_class_key): New function.
        (structsp): Call it.Read from remote host gcc.gnu.org: Connection reset by peer
testsuite:
        * g++.dg/other/classkey1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@50230 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/parse.y
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/classkey1.C [new file with mode: 0644]

index f1c25a4..013b826 100644 (file)
@@ -1,3 +1,11 @@
+2002-03-02  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/775
+       * decl.c (lookup_tag): Only reject enum/class mismatch, not
+       class/union mismatch.
+       * parse.y (check_class_key): New function.
+       (structsp): Call it.
+
 2002-03-01  Michael Matz  <matz@suse.de>
 
        * typeck.c (cp_pointer_int_sum): Complete inner type which is
index d4ea80d..854a2c2 100644 (file)
@@ -5345,7 +5345,7 @@ lookup_tag (form, name, binding_level, thislevel_only)
            if (old && DECL_ORIGINAL_TYPE (TYPE_NAME (old)))
              old = NULL_TREE;
            if (old && TREE_CODE (old) != form
-               && !(form != ENUMERAL_TYPE && TREE_CODE (old) == TEMPLATE_DECL))
+               && (form == ENUMERAL_TYPE || TREE_CODE (old) == ENUMERAL_TYPE))
              {
                error ("`%#D' redeclared as %C", old, form);
                return NULL_TREE;
@@ -5361,14 +5361,12 @@ lookup_tag (form, name, binding_level, thislevel_only)
            if (TREE_PURPOSE (tail) == name)
              {
                enum tree_code code = TREE_CODE (TREE_VALUE (tail));
-               /* Should tighten this up; it'll probably permit
-                  UNION_TYPE and a struct template, for example.  */
+               
                if (code != form
-                   && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL))
+                   && (form == ENUMERAL_TYPE || code == ENUMERAL_TYPE))
                  {
                    /* Definition isn't the kind we were looking for.  */
-                   error ("`%#D' redeclared as %C", TREE_VALUE (tail),
-                             form);
+                   error ("`%#D' redeclared as %C", TREE_VALUE (tail), form);
                    return NULL_TREE;
                  }
                return TREE_VALUE (tail);
index e6bdc9a..fd53a85 100644 (file)
@@ -87,7 +87,8 @@ static tree parse_field PARAMS ((tree, tree, tree, tree));
 static tree parse_bitfield0 PARAMS ((tree, tree, tree, tree, tree));
 static tree parse_bitfield PARAMS ((tree, tree, tree));
 static tree parse_method PARAMS ((tree, tree, tree));
-static void frob_specs PARAMS ((tree, tree)); 
+static void frob_specs PARAMS ((tree, tree));
+static void check_class_key PARAMS ((tree, tree));
 
 /* Cons up an empty parameter list.  */
 static inline tree
@@ -208,6 +209,17 @@ parse_method (declarator, specs_attrs, lookups)
   return d;
 }
 
+static void
+check_class_key (key, aggr)
+     tree key;
+     tree aggr;
+{
+  if ((key == union_type_node) != (TREE_CODE (aggr) == UNION_TYPE))
+    pedwarn ("`%s' tag used in naming `%#T'",
+            key == union_type_node ? "union"
+            : key == record_type_node ? "struct" : "class", aggr);
+}
+
 void
 cp_parse_init ()
 {
@@ -2292,6 +2304,7 @@ structsp:
                      xref_basetypes (current_aggr, $1.t, type, $2);
                    }
                  $1.t = begin_class_definition (TREE_TYPE ($1.t)); 
+                 check_class_key (current_aggr, $1.t);
                   current_aggr = NULL_TREE; }
           opt.component_decl_list '}' maybe_attribute
                { 
@@ -2326,6 +2339,7 @@ structsp:
                {
                  $$.t = TREE_TYPE ($1.t);
                  $$.new_type_flag = $1.new_type_flag;
+                 check_class_key (current_aggr, $$.t);
                }
        ;
 
index 6dabbc7..5be459f 100644 (file)
@@ -1,3 +1,7 @@
+2002-03-02  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/other/classkey1.C: New test.
+
 2002-03-01  Richard Henderson  <rth@redhat.com>
 
        * gcc.c-torture/compile/981223-1.x: New.
diff --git a/gcc/testsuite/g++.dg/other/classkey1.C b/gcc/testsuite/g++.dg/other/classkey1.C
new file mode 100644 (file)
index 0000000..17fb540
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 28 Feb 2002 <nathan@codesourcery.com>
+
+// PR 775. Some mismatches which were broken.
+
+template <class T> struct A {};
+union A<int> a; // { dg-error "`union' tag" "" }
+
+template <> union A<float> {}; // { dg-error "`union' tag" "" }
+
+struct B {};
+union B b;     // { dg-error "`union' tag" "" }
+
+union C {};
+class C c;     // { dg-error "`class' tag" "" }