This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PING] Re: [PATCH] c++/67913, 67917 - fix new expression with wrong number of elements
- From: Jason Merrill <jason at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 2 Nov 2015 23:55:42 -0500
- Subject: Re: [PING] Re: [PATCH] c++/67913, 67917 - fix new expression with wrong number of elements
- Authentication-results: sourceware.org; auth=none
- References: <562573AF dot 7080105 at gmail dot com> <562EDC2C dot 7080507 at gmail dot com>
On 10/26/2015 10:06 PM, Martin Sebor wrote:
+ if (TREE_CONSTANT (maybe_constant_value (outer_nelts)))
+ {
+ if (tree_int_cst_lt (max_outer_nelts_tree, outer_nelts))
maybe_constant_value may return a constant, but that doesn't mean that
outer_nelts was already constant; if it wasn't, the call to
tree_int_cst_lt will fail.
+ tree nelts_save = nelts;
+ nelts = maybe_constant_value (nelts);
+
+ if (!TREE_CONSTANT (nelts))
+ nelts = nelts_save;
+
+ /* The expression in a noptr-new-declarator is erroneous if it's of
+ non-class type and its value before converting to std::size_t is
+ less than zero. ... If the expression is a constant expression,
+ the program is ill-fomed. */
+ if (TREE_CONSTANT (nelts) && tree_int_cst_sgn (nelts) == -1)
+ {
+ if (complain & tf_error)
+ error ("size of array is negative");
+ return error_mark_node;
+ }
Since we're moving toward delayed folding, I'd prefer to use the result
of maybe_constant_value only for this diagnostic, and then continue to
pass the unfolded value along.
Jason