Commit b655f214 by Mark Mitchell Committed by Mark Mitchell

re PR c++/27210 (ICE on c++ template)

	PR c++/27210
	* cp-tree.h (cp_save_expr): New function.
	* init.c (build_new): Correct logic for zero-element array
	warning.  Use cp_save_expr.
	* tree.c (cp_save_expr): New function.
	PR c++/27210
	* g++.dg/warn/new1.C: New test.
	* g++.dg/template/new5.C: Likewise.

From-SVN: r113958
parent 357f19a0
2006-05-21 Mark Mitchell <mark@codesourcery.com>
PR c++/27210
* cp-tree.h (cp_save_expr): New function.
* init.c (build_new): Correct logic for zero-element array
warning. Use cp_save_expr.
* tree.c (cp_save_expr): New function.
2006-05-21 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 2006-05-21 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27398 PR c++/27398
......
...@@ -4336,6 +4336,7 @@ extern int cp_auto_var_in_fn_p (tree,tree); ...@@ -4336,6 +4336,7 @@ extern int cp_auto_var_in_fn_p (tree,tree);
extern tree fold_if_not_in_template (tree); extern tree fold_if_not_in_template (tree);
extern tree rvalue (tree); extern tree rvalue (tree);
extern tree convert_bitfield_to_declared_type (tree); extern tree convert_bitfield_to_declared_type (tree);
extern tree cp_save_expr (tree);
/* in typeck.c */ /* in typeck.c */
extern int string_conv_p (tree, tree, int); extern int string_conv_p (tree, tree, int);
......
...@@ -2088,9 +2088,22 @@ build_new (tree placement, tree type, tree nelts, tree init, ...@@ -2088,9 +2088,22 @@ build_new (tree placement, tree type, tree nelts, tree init,
{ {
if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false)) if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false))
pedwarn ("size in array new must have integral type"); pedwarn ("size in array new must have integral type");
nelts = save_expr (cp_convert (sizetype, nelts)); nelts = cp_save_expr (cp_convert (sizetype, nelts));
if (nelts == integer_zero_node) /* It is valid to allocate a zero-element array:
warning (0, "zero size array reserves no space");
[expr.new]
When the value of the expression in a direct-new-declarator
is zero, the allocation function is called to allocate an
array with no elements. The pointer returned by the
new-expression is non-null. [Note: If the library allocation
function is called, the pointer returned is distinct from the
pointer to any other object.]
However, that is not generally useful, so we issue a
warning. */
if (integer_zerop (nelts))
warning (0, "allocating zero-element array");
} }
/* ``A reference cannot be created by the new operator. A reference /* ``A reference cannot be created by the new operator. A reference
......
...@@ -2083,6 +2083,20 @@ cp_auto_var_in_fn_p (tree var, tree fn) ...@@ -2083,6 +2083,20 @@ cp_auto_var_in_fn_p (tree var, tree fn)
&& nonstatic_local_decl_p (var)); && nonstatic_local_decl_p (var));
} }
/* Like save_expr, but for C++. */
tree
cp_save_expr (tree expr)
{
/* There is no reason to create a SAVE_EXPR within a template; if
needed, we can create the SAVE_EXPR when instantiating the
template. Furthermore, the middle-end cannot handle C++-specific
tree codes. */
if (processing_template_decl)
return expr;
return save_expr (expr);
}
/* Initialize tree.c. */ /* Initialize tree.c. */
void void
......
2006-05-21 Mark Mitchell <mark@codesourcery.com>
PR c++/27210
* g++.dg/warn/new1.C: New test.
* g++.dg/template/new5.C: Likewise.
2006-05-21 Roger Sayle <roger@eyesopen.com> 2006-05-21 Roger Sayle <roger@eyesopen.com>
* gcc.target/i386/20060512-1.c: Add -msse2 command line option. * gcc.target/i386/20060512-1.c: Add -msse2 command line option.
// PR c++/27210
template <class foo> class junk {
void bar(int a)
{
unsigned char *c = new unsigned char[a*sizeof(foo)];
}
};
void f() {
new int[0]; // { dg-warning "zero" }
}
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