Commit abff8e06 by Jason Merrill

class.c (instantiate_type): Don't just return a known type if it's wrong.

	* class.c (instantiate_type): Don't just return a known type if
 	it's wrong.
	* class.c (instantiate_type): Remove handling of FUNCTION_DECL
	since that code could never be reached.
	* error.c (dump_decl): Avoid aborting in the midst of printing an
	error message about an illegal template declaration.
	* parse.y (structsp): Print an error message, rather than crashing,
	when a class-head does not name a class.
	* pt.c (convert_nontype_argument):  Allow REAL_TYPE and COMPLEX_TYPE
	template arguments as a g++ extension.
	* cp-tree.def (ALIGNOF_EXPR): New tree code.
	* decl2.c (grok_alignof): If processing_template_decl, just store
	the expression.
	* typeck.c (c_alignof): Likewise.
	* decl2.c (build_expr_from_tree): Handle ALIGNOF_EXPR.
	* error.c (dump_expr): Likewise.
	* pt.c (tsubst_copy): Likewise.
	* tree.c (cp_tree_equal): Likewise.
	* pt.c (uses_template_parms): Correctly determine whether or not a
	SIZEOF_EXPR/ALIGNOF_EXPR uses template parameters so that constant
	folding can be done.

From-SVN: r17545
parent 76d31c63
Wed Jan 28 23:14:44 1998 Jason Merrill <jason@yorick.cygnus.com>
* class.c (instantiate_type): Don't just return a known type if
it's wrong.
Wed Jan 28 11:04:07 1998 Mark Mitchell <mmitchell@usa.net>
* class.c (instantiate_type): Remove handling of FUNCTION_DECL
since that code could never be reached.
* error.c (dump_decl): Avoid aborting in the midst of printing an
error message about an illegal template declaration.
* parse.y (structsp): Print an error message, rather than crashing,
when a class-head does not name a class.
* pt.c (convert_nontype_argument): Allow REAL_TYPE and COMPLEX_TYPE
template arguments as a g++ extension.
* cp-tree.def (ALIGNOF_EXPR): New tree code.
* decl2.c (grok_alignof): If processing_template_decl, just store
the expression.
* typeck.c (c_alignof): Likewise.
* decl2.c (build_expr_from_tree): Handle ALIGNOF_EXPR.
* error.c (dump_expr): Likewise.
* pt.c (tsubst_copy): Likewise.
* tree.c (cp_tree_equal): Likewise.
* pt.c (uses_template_parms): Correctly determine whether or not a
SIZEOF_EXPR/ALIGNOF_EXPR uses template parameters so that constant
folding can be done.
* cp-tree.h (grok_enum_decls): Remove type parameter.
* decl.c (grok_enum_decls): Likewise.
* decl2.c (grok_x_components): Call grok_enum_decls
......
......@@ -4979,7 +4979,14 @@ instantiate_type (lhstype, rhs, complain)
}
if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
return rhs;
{
if (comptypes (lhstype, TREE_TYPE (rhs), 1))
return rhs;
if (complain)
cp_error ("argument of type `%T' does not match `%T'",
TREE_TYPE (rhs), lhstype);
return error_mark_node;
}
rhs = copy_node (rhs);
......@@ -5425,16 +5432,6 @@ instantiate_type (lhstype, rhs, complain)
case ERROR_MARK:
return error_mark_node;
case FUNCTION_DECL:
if (!comptypes (lhstype, TREE_TYPE (rhs), 1))
{
if (complain)
cp_error ("%D is not of type %T", rhs, lhstype);
return error_mark_node;
}
else
return rhs;
default:
my_friendly_abort (185);
return error_mark_node;
......
......@@ -142,6 +142,7 @@ DEFTREECODE (CONST_CAST_EXPR, "const_cast_expr", '1', 1)
DEFTREECODE (STATIC_CAST_EXPR, "static_cast_expr", '1', 1)
DEFTREECODE (DYNAMIC_CAST_EXPR, "dynamic_cast_expr", '1', 1)
DEFTREECODE (SIZEOF_EXPR, "sizeof_expr", '1', 1)
DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", '1', 1)
DEFTREECODE (ARROW_EXPR, "arrow_expr", 'e', 1)
DEFTREECODE (DOTSTAR_EXPR, "dotstar_expr", 'e', 2)
DEFTREECODE (TYPEID_EXPR, "typeid_expr", 'e', 1)
......
......@@ -1119,6 +1119,9 @@ grok_alignof (expr)
tree best, t;
int bestalign;
if (processing_template_decl)
return build_min (ALIGNOF_EXPR, sizetype, expr);
if (TREE_CODE (expr) == COMPONENT_REF
&& DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
error ("`__alignof__' applied to a bit-field");
......@@ -3505,11 +3508,12 @@ build_expr_from_tree (t)
build_expr_from_tree (TREE_OPERAND (t, 1)));
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
{
tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
r = TREE_TYPE (r);
return c_sizeof (r);
return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r);
}
case MODOP_EXPR:
......
......@@ -812,7 +812,8 @@ dump_decl (t, v)
break;
default:
my_friendly_abort (353);
/* This case can occur with some illegal code. */
dump_type (TREE_TYPE (t), v);
}
}
break;
......@@ -1586,7 +1587,14 @@ dump_expr (t, nop)
break;
case SIZEOF_EXPR:
OB_PUTS ("sizeof (");
case ALIGNOF_EXPR:
if (TREE_CODE (t) == SIZEOF_EXPR)
OB_PUTS ("sizeof (");
else
{
my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
OB_PUTS ("__alignof__ (");
}
if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
dump_type (TREE_OPERAND (t, 0), 0);
else
......
......@@ -2355,13 +2355,21 @@ structsp:
}
| class_head %prec EMPTY
{
$$.t = $1;
$$.new_type_flag = 0;
/* struct B: public A; is not accepted by the WP grammar. */
if (TYPE_BINFO_BASETYPES ($$.t) && !TYPE_SIZE ($$.t)
&& ! TYPE_BEING_DEFINED ($$.t))
cp_error ("base clause without member specification for `%#T'",
$$.t);
if (TYPE_BINFO ($1) == NULL_TREE)
{
cp_error ("%T is not a class type", $1);
$$.t = error_mark_node;
}
else
{
$$.t = $1;
/* struct B: public A; is not accepted by the WP grammar. */
if (TYPE_BINFO_BASETYPES ($$.t) && !TYPE_SIZE ($$.t)
&& ! TYPE_BEING_DEFINED ($$.t))
cp_error ("base clause without member specification for `%#T'",
$$.t);
}
}
;
......
......@@ -1498,6 +1498,14 @@ convert_nontype_argument (type, expr)
just converting one integral constant expression to another. */
return digest_init (type, expr, (tree*) 0);
case REAL_TYPE:
case COMPLEX_TYPE:
/* These are g++ extensions. */
if (TREE_CODE (expr_type) != TREE_CODE (type))
return error_mark_node;
return digest_init (type, expr, (tree*) 0);
case POINTER_TYPE:
{
tree type_pointed_to = TREE_TYPE (type);
......@@ -2539,12 +2547,15 @@ uses_template_parms (t)
case CONST_CAST_EXPR:
case STATIC_CAST_EXPR:
case DYNAMIC_CAST_EXPR:
case SIZEOF_EXPR:
case ARROW_EXPR:
case DOTSTAR_EXPR:
case TYPEID_EXPR:
return 1;
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
return uses_template_parms (TREE_OPERAND (t, 0));
default:
switch (TREE_CODE_CLASS (TREE_CODE (t)))
{
......@@ -4004,6 +4015,7 @@ tsubst_copy (t, args, nargs, in_decl)
case ADDR_EXPR:
case CONVERT_EXPR: /* Unary + */
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
case ARROW_EXPR:
case THROW_EXPR:
case TYPEID_EXPR:
......
......@@ -2074,6 +2074,7 @@ cp_tree_equal (t1, t2)
&& TEMPLATE_CONST_LEVEL (t1) == TEMPLATE_CONST_LEVEL (t2);
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
return 0;
if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t1, 0))) == 't')
......
......@@ -1474,6 +1474,9 @@ c_alignof (type)
enum tree_code code = TREE_CODE (type);
tree t;
if (processing_template_decl)
return build_min (ALIGNOF_EXPR, sizetype, type);
if (code == FUNCTION_TYPE || code == METHOD_TYPE)
return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment