OSDN Git Service

PR c/7353 redux
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 2 Nov 2002 02:17:41 +0000 (02:17 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 2 Nov 2002 02:17:41 +0000 (02:17 +0000)
cp:
* decl2.c (grokfield): Reject TYPE_DECLs with initializers.
testsuite:
* g++.dg/ext/typedef-init.C, gcc.dg/typedef-init.C:
Add some more cases.

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

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/typedef-init.C
gcc/testsuite/gcc.dg/typedef-init.c

index 8b0d774..ce94b3a 100644 (file)
@@ -1,3 +1,8 @@
+2002-11-01  Zack Weinberg  <zack@codesourcery.com>
+
+       PR c/7353 redux
+       * decl2.c (grokfield): Reject TYPE_DECLs with initializers.
+
 2002-10-30  Jason Merrill  <jason@redhat.com>
 
        PR c++/8186
@@ -21,7 +26,7 @@
 
        PR c++/8149
        * decl.c (make_typename_type): Issue errors about invalid results.
-       
+
 2002-10-30  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        Core issue 287, PR c++/7639
@@ -77,7 +82,7 @@
        * pt.c (build_template_decl): Don't set it.
        (tsubst_decl): Likewise.
        * typeck.c (expand_ptrmemfunc_cst): Don't use it.
-               
+
        * class.c (build_vtbl_initializer): Don't use build_vtable_entry.
        (build_vtable_entry): Remove.
        * cp-tree.h (BINFO_VIRTUALS): Expand documentation.
index 9461174..93b643f 100644 (file)
@@ -915,7 +915,13 @@ grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
     /* friend or constructor went bad.  */
     return value;
   if (TREE_TYPE (value) == error_mark_node)
-    return error_mark_node;  
+    return error_mark_node;
+
+  if (TREE_CODE (value) == TYPE_DECL && init)
+    {
+      error ("typedef `%D' is initialized (use __typeof__ instead)", value);
+      init = NULL_TREE;
+    }
 
   /* Pass friendly classes back.  */
   if (TREE_CODE (value) == VOID_TYPE)
index 90877e8..2b88c1f 100644 (file)
@@ -1,3 +1,8 @@
+2002-11-01  Zack Weinberg  <zack@codesourcery.com>
+
+       * g++.dg/ext/typedef-init.C, gcc.dg/typedef-init.C:
+       Add some more cases.
+
 2002-11-01  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/8391
index 5602783..1b2a05d 100644 (file)
@@ -5,10 +5,29 @@
    it's been broken since GCC 3.0 (caused ICE) and we have now removed
    the extension.  See PR c/7353.
 
-   C++ issues a warning in addition to the error, since this construct
-   appears to be a case of implicit int (forbidden in std. C++) until
-   we get to the equals sign.  */
+   For cases A and C, C++ issues a warning in addition to the error,
+   since this construct appears to be a case of implicit int
+   (forbidden in std. C++) until we get to the equals sign.  */
 
-typedef A = 0;  /* { dg-error "initialized" "typedef A = B" } */
-                /* { dg-warning "no type" "also warns" { target *-*-* } 12 } */
-A a;            /* { dg-bogus "" "no error cascade" } */
+/* Case A: just the bare name = initializer.  */
+
+typedef A = 0;  /* { dg-error "initialized" "A" } */
+                /* { dg-warning "no type" "A warns" { target *-*-* } 14 } */
+A a;            /* { dg-bogus "" "A error cascade" } */
+
+/* Case B: with a type also.  */
+
+typedef int B = 0;  /* { dg-error "initialized" "B" } */
+B b;               /* { dg-bogus "" "B error cascade" } */
+
+/* C and D are the same as A and B, but wrapped in a structure;
+   field declarations go by a different code path in C++ (ick).  */
+
+struct S {
+  typedef C = 0; /* { dg-error "initialized" "C" } */
+                 /* { dg-warning "no type" "C warns" { target *-*-* } 27 } */
+  C c;          /* { dg-bogus "" "C error cascade" } */
+
+  typedef int D = 0; /* { dg-error "initialized" "D" } */
+  D d;              /* { dg-bogus "" "D error cascade" } */
+};
index 9cb4830..52928da 100644 (file)
@@ -5,5 +5,12 @@
    it's been broken since GCC 3.0 (caused ICE) and we have now removed
    the extension.  See PR c/7353.  */
 
-typedef A = 0;  /* { dg-error "initialized" "typedef A = B" } */
-A a;            /* { dg-bogus "" "no error cascade" } */
+/* Case A: just the bare name = initializer.  */
+
+typedef A = 0;  /* { dg-error "initialized" "A" } */
+A a;            /* { dg-bogus "" "A error cascade" } */
+
+/* Case B: with a type also.  */
+
+typedef int B = 0;  /* { dg-error "initialized" "B" } */
+B b;               /* { dg-bogus "" "B error cascade" } */