This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for miscellaneous crashes
- To: egcs-patches at egcs dot cygnus dot com
- Subject: C++ PATCH for miscellaneous crashes
- From: mitchell at codesourcery dot com
- Date: Mon, 17 May 1999 16:12:33 -0700
- Organization: CodeSourcery, LLC
This patch fixes some of the problems Franz found by using
--enable-checking. Some of these were very nasty, and could have led
to hard-to-find crashes, or even bad code generation. I'll probably
fix some more of these soon.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-05-17 Mark Mitchell <mark@codesourcery.com>
* cp-tree.def (TEMPLATE_ID_EXPR): Update documentation.
* decl.c (grokfndecl): Don't allow inline declarations of friend
template specializations, or friend template specializations with
default arguments.
* pt.c (tsubst): Handle substitution into array types that does
not yield a fixed upper bound, even when not processing a
template.
(tsubst_copy): Deal with the fact that the second operand to a
TEMPLATE_ID_EXPR may be NULL_TREE, a TREE_LIST, or a TREE_VEC.
* search.c (marked_pushdecls_p): Don't descend into
TEMPLATE_TYPE_PARMs and the like.
(unmarked_pushdecls_p): Likewise.
Index: testsuite/g++.old-deja/g++.pt/friend37.C
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.pt/friend37.C,v
retrieving revision 1.3
diff -u -p -r1.3 friend37.C
--- friend37.C 1998/12/16 21:56:48 1.3
+++ friend37.C 1999/05/17 22:53:27
@@ -1,8 +1,7 @@
// Build don't link:
// Simplified from report by Volker Dobler <volker@hugo.physik.uni-konstanz.de>
-// crash test - XFAIL *-*-*
-
template <class T> class A {
- friend int ice<>( int k=0 ); // ERROR - undeclared
+ friend int ice<>( int k=0 ); // ERROR - default argument
+ friend inline int f<>(double); // ERROR - inline
};
Index: testsuite/cp/cp-tree.def
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.def,v
retrieving revision 1.27
diff -u -p -r1.27 cp-tree.def
--- cp-tree.def 1999/04/16 18:06:31 1.27
+++ cp-tree.def 1999/05/17 22:53:28
@@ -173,10 +173,10 @@ DEFTREECODE (USING_DECL, "using_decl", '
DEFTREECODE (DEFAULT_ARG, "default_arg", 'c', 2)
/* A template-id, like foo<int>. The first operand is the template.
- The second is the list of explicitly specified arguments. The
- template will be a FUNCTION_DECL, TEMPLATE_DECL, or an OVERLOAD.
- If the template-id refers to a member template, the template may be
- an IDENTIFIER_NODE. */
+ The second is the TREE_LIST or TREE_VEC of explicitly specified
+ arguments. The template will be a FUNCTION_DECL, TEMPLATE_DECL, or
+ an OVERLOAD. If the template-id refers to a member template, the
+ template may be an IDENTIFIER_NODE. */
DEFTREECODE (TEMPLATE_ID_EXPR, "template_id_expr", 'e', 2)
/* An association between name and entity. Parameters are the scope
Index: testsuite/cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.356
diff -u -p -r1.356 decl.c
--- decl.c 1999/05/13 15:42:53 1.356
+++ decl.c 1999/05/17 22:53:36
@@ -8710,6 +8710,7 @@ grokfndecl (ctype, type, declarator, ori
{
tree cname, decl;
int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
+ int has_default_arg = 0;
tree t;
if (ctype)
@@ -8826,7 +8827,7 @@ grokfndecl (ctype, type, declarator, ori
if (TREE_PURPOSE (t)
&& TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG)
{
- add_defarg_fn (decl);
+ has_default_arg = 1;
break;
}
@@ -8847,6 +8848,7 @@ grokfndecl (ctype, type, declarator, ori
return NULL_TREE;
}
+
/* A friend declaration of the form friend void f<>(). Record
the information in the TEMPLATE_ID_EXPR. */
SET_DECL_IMPLICIT_INSTANTIATION (decl);
@@ -8854,8 +8856,25 @@ grokfndecl (ctype, type, declarator, ori
= perm_tree_cons (TREE_OPERAND (orig_declarator, 0),
TREE_OPERAND (orig_declarator, 1),
NULL_TREE);
+
+ if (has_default_arg)
+ {
+ cp_error ("default arguments are not allowed in declaration of friend template specialization `%D'",
+ decl);
+ return NULL_TREE;
+ }
+
+ if (inlinep)
+ {
+ cp_error ("`inline' is not allowed in declaration of friend template specialization `%D'",
+ decl);
+ return NULL_TREE;
+ }
}
}
+
+ if (has_default_arg)
+ add_defarg_fn (decl);
/* Plain overloading: will not be grok'd by grokclassfn. */
if (! ctype && ! processing_template_decl
Index: testsuite/cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.295
diff -u -p -r1.295 pt.c
--- pt.c 1999/05/10 12:12:55 1.295
+++ pt.c 1999/05/17 22:53:42
@@ -6128,7 +6128,12 @@ tsubst (t, args, complain, in_decl)
if (max == error_mark_node)
return error_mark_node;
- if (processing_template_decl)
+ if (processing_template_decl
+ /* When providing explicit arguments to a template
+ function, but leaving some arguments for subsequent
+ deduction, MAX may be template-dependent even if we're
+ not PROCESSING_TEMPLATE_DECL. */
+ || TREE_CODE (max) != INTEGER_CST)
{
tree itype = make_node (INTEGER_TYPE);
TYPE_MIN_VALUE (itype) = size_zero_node;
@@ -6908,9 +6913,20 @@ tsubst_copy (t, args, complain, in_decl)
/* Substituted template arguments */
tree targs = tsubst_copy (TREE_OPERAND (t, 1), args, complain,
in_decl);
- tree chain;
- for (chain = targs; chain; chain = TREE_CHAIN (chain))
- TREE_VALUE (chain) = maybe_fold_nontype_arg (TREE_VALUE (chain));
+
+ if (targs && TREE_CODE (targs) == TREE_LIST)
+ {
+ tree chain;
+ for (chain = targs; chain; chain = TREE_CHAIN (chain))
+ TREE_VALUE (chain) = maybe_fold_nontype_arg (TREE_VALUE (chain));
+ }
+ else if (targs)
+ {
+ int i;
+ for (i = 0; i < TREE_VEC_LENGTH (targs); ++i)
+ TREE_VEC_ELT (targs, i)
+ = maybe_fold_nontype_arg (TREE_VEC_ELT (targs, i));
+ }
return lookup_template_function
(tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl), targs);
Index: testsuite/cp/search.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/search.c,v
retrieving revision 1.102
diff -u -p -r1.102 search.c
--- search.c 1999/05/03 15:08:29 1.102
+++ search.c 1999/05/17 22:53:44
@@ -2122,7 +2122,8 @@ marked_pushdecls_p (binfo, data)
tree binfo;
void *data ATTRIBUTE_UNUSED;
{
- return BINFO_PUSHDECLS_MARKED (binfo) ? binfo : NULL_TREE;
+ return (CLASS_TYPE_P (BINFO_TYPE (binfo))
+ && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
}
static tree
@@ -2130,7 +2131,8 @@ unmarked_pushdecls_p (binfo, data)
tree binfo;
void *data ATTRIBUTE_UNUSED;
{
- return !BINFO_PUSHDECLS_MARKED (binfo) ? binfo : NULL_TREE;
+ return (CLASS_TYPE_P (BINFO_TYPE (binfo))
+ && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
}
#if 0