diff options
author | Mark Mitchell <mark@codesourcery.com> | 2006-05-21 17:23:59 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2006-05-21 17:23:59 +0000 |
commit | b655f214fa8e0297c3ef849c8a4f403d85777d13 (patch) | |
tree | 43334d7f67ff997edd619b6c7ddc92b7245fdfaa | |
parent | 357f19a0db6794478e915ad7b1e01b7efe52d536 (diff) | |
download | gcc-b655f214fa8e0297c3ef849c8a4f403d85777d13.zip gcc-b655f214fa8e0297c3ef849c8a4f403d85777d13.tar.gz gcc-b655f214fa8e0297c3ef849c8a4f403d85777d13.tar.bz2 |
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
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
-rw-r--r-- | gcc/cp/init.c | 19 | ||||
-rw-r--r-- | gcc/cp/tree.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/new5.C | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/new1.C | 3 |
7 files changed, 57 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 13f25f0..251d21a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +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> PR c++/27398 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ed5c330..044fe26 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4336,6 +4336,7 @@ extern int cp_auto_var_in_fn_p (tree,tree); extern tree fold_if_not_in_template (tree); extern tree rvalue (tree); extern tree convert_bitfield_to_declared_type (tree); +extern tree cp_save_expr (tree); /* in typeck.c */ extern int string_conv_p (tree, tree, int); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e9528f2..533f9fb 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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)) pedwarn ("size in array new must have integral type"); - nelts = save_expr (cp_convert (sizetype, nelts)); - if (nelts == integer_zero_node) - warning (0, "zero size array reserves no space"); + nelts = cp_save_expr (cp_convert (sizetype, nelts)); + /* It is valid to allocate a zero-element array: + + [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 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 81b37d6..fdf491a 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2083,6 +2083,20 @@ cp_auto_var_in_fn_p (tree var, tree fn) && 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. */ void diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6adae33..b3d146d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +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> * gcc.target/i386/20060512-1.c: Add -msse2 command line option. diff --git a/gcc/testsuite/g++.dg/template/new5.C b/gcc/testsuite/g++.dg/template/new5.C new file mode 100644 index 0000000..a2c5601 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/new5.C @@ -0,0 +1,9 @@ +// PR c++/27210 + +template <class foo> class junk { + void bar(int a) + { + unsigned char *c = new unsigned char[a*sizeof(foo)]; + } +}; + diff --git a/gcc/testsuite/g++.dg/warn/new1.C b/gcc/testsuite/g++.dg/warn/new1.C new file mode 100644 index 0000000..6b78368 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/new1.C @@ -0,0 +1,3 @@ +void f() { + new int[0]; // { dg-warning "zero" } +} |