aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@markmitchell.com>1998-08-23 14:40:50 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1998-08-23 14:40:50 +0000
commitd7ceab7b4b7a2b4f91db42526a6cbdc97393d8e8 (patch)
tree745bd98cd8da93d0cd072f1007a7f6506fa51d02 /gcc
parent03d0f4af2d5607dacc56b946b49e024e71dd7fb7 (diff)
downloadgcc-d7ceab7b4b7a2b4f91db42526a6cbdc97393d8e8.zip
gcc-d7ceab7b4b7a2b4f91db42526a6cbdc97393d8e8.tar.gz
gcc-d7ceab7b4b7a2b4f91db42526a6cbdc97393d8e8.tar.bz2
decl.c (grokdeclarator): Complain about in-class initialization of aggregates and/or references.
* 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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/decl.c24
-rw-r--r--gcc/cp/pt.c1
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/crash2.C9
4 files changed, 31 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index bf714bf..4fa3740 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a93685d..5940996 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f156fe1..79a00fa 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
index 0000000..93e0a6e
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/crash2.C
@@ -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) {}
+};