decl.c (grokdeclarator): Complain about in-class initialization of aggregates and...
authorMark Mitchell <mark@markmitchell.com>
Sun, 23 Aug 1998 14:40:50 +0000 (14:40 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 23 Aug 1998 14:40:50 +0000 (14:40 +0000)
* decl.c (grokdeclarator): Complain about in-class initialization
of aggregates and/or references.
* pt.c (process_template_parm): Clear IS_AGGR_TYPE for
TEMPLATE_TYPE_PARMs.

From-SVN: r21916

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c
gcc/testsuite/g++.old-deja/g++.other/crash2.C [new file with mode: 0644]

index bf714bf06f7adb663b9f5cdbe77c47accc1facfa..4fa37401874de6e97ebbfb2d84bd72398a7df54f 100644 (file)
@@ -1,5 +1,10 @@
 1998-08-23  Mark Mitchell  <mark@markmitchell.com>
 
+       * decl.c (grokdeclarator): Complain about in-class initialization
+       of aggregates and/or references.
+       * pt.c (process_template_parm): Clear IS_AGGR_TYPE for
+       TEMPLATE_TYPE_PARMs. 
+
        * decl2.c (grok_array_decl): Add comment.
        (mark_used): Don't instantiate an explicit instantiation.
        * friend.c (make_friend_class): Remove bogus comment.  Fix check
index a93685d810cdd92c984d67754a2cc35ef2f3d311..5940996510c10213c262e5d2b966efdb952129b2 100644 (file)
@@ -10431,15 +10431,23 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                   but not both.  If it appears in the class, the member is
                   a member constant.  The file-scope definition is always
                   required.  */
-               if (! constp)
-                 /* According to Mike Stump, we generate bad code for
-                    this case, so we might as well always make it an
-                    error.  */
+               if (IS_AGGR_TYPE (type)
+                   || TREE_CODE (type) == REFERENCE_TYPE)
+                 {
+                   cp_error ("in-class initialization of static data member of non-integral type `%T'", 
+                             type);
+                   /* If we just return the declaration, crashes will
+                      sometimes occur.  We therefore return
+                      void_type_node, as if this was a friend
+                      declaration, to cause callers to completely
+                      ignore this declaration.  */
+                   return void_type_node;
+                 }
+               else if (!constp)
                  cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
                            declarator);
-               
-               if (pedantic && ! INTEGRAL_TYPE_P (type) 
-                   && !uses_template_parms (type))
+               else if (pedantic && ! INTEGRAL_TYPE_P (type) 
+                        && !uses_template_parms (type))
                  cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type);
              }
 
@@ -10452,7 +10460,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
 
                /* C++ allows static class members.
                   All other work for this is done by grokfield.
-                  This VAR_DECL is built by build_lang_field_decl.
+                  This VAR_DCL is built by build_lang_field_decl.
                   All other VAR_DECLs are built by build_decl.  */
                decl = build_lang_field_decl (VAR_DECL, declarator, type);
                TREE_STATIC (decl) = 1;
index f156fe186bb8ba85332aee9f2652ae8d94d140c0..79a00fad65c98dc8b9582f76f1c271285f6ca081 100644 (file)
@@ -1590,6 +1590,7 @@ process_template_parm (list, next)
       else
        {
          t = make_lang_type (TEMPLATE_TYPE_PARM);
+         IS_AGGR_TYPE (t) = 0;
          /* parm is either IDENTIFIER_NODE or NULL_TREE */
          decl = build_decl (TYPE_DECL, parm, t);
        }
diff --git a/gcc/testsuite/g++.old-deja/g++.other/crash2.C b/gcc/testsuite/g++.old-deja/g++.other/crash2.C
new file mode 100644 (file)
index 0000000..93e0a6e
--- /dev/null
@@ -0,0 +1,9 @@
+// Build don't link:
+
+struct A {
+  int rep;
+  static const A a(0); // ERROR - initialization
+  static const A b = 3; // ERROR - initialization
+  static const A& c = 2; // ERROR - initialization
+  A(int x) : rep(x) {}
+};