Skip to content
Snippets Groups Projects
Commit 096f034a authored by Patrick Palka's avatar Patrick Palka
Browse files

c++: unevaluated array new-expr size constantness [PR108219]


Here we're mishandling the unevaluated array new-expressions due to a
supposed non-constant array size ever since r12-5253-g4df7f8c79835d569
made us no longer perform constant evaluation of non-manifestly-constant
expressions within unevaluated contexts.  This shouldn't make a difference
here since the array sizes are constant literals, except they're expressed
as NON_LVALUE_EXPR location wrappers around INTEGER_CST, wrappers which
used to get stripped as part of constant evaluation and now no longer do.
Moreover it means build_vec_init can't constant fold the MINUS_EXPR
'maxindex' passed from build_new_1 when in an unevaluated context (since
it tries reducing it via maybe_constant_value called with mce_unknown).

This patch fixes these issues by making maybe_constant_value (and
fold_non_dependent_expr) try folding an unevaluated non-manifestly-constant
operand via fold(), as long as it simplifies to a simple constant, rather
than doing no simplification at all.  This covers e.g. simple arithmetic
and casts including stripping of location wrappers around INTEGER_CST.

In passing, this patch also fixes maybe_constant_value to avoid constant
evaluating an unevaluated operand when called with mce_false, by adjusting
the early exit test appropriately.

Co-authored-by: default avatarJason Merrill <jason@redhat.com>

	PR c++/108219
	PR c++/108218

gcc/cp/ChangeLog:

	* constexpr.cc (fold_to_constant): Define.
	(maybe_constant_value): Move up early exit test for unevaluated
	operands.  Try reducing an unevaluated operand to a constant via
	fold_to_constant.
	(fold_non_dependent_expr_template): Add early exit test for
	CONSTANT_CLASS_P nodes.  Try reducing an unevaluated operand
	to a constant via fold_to_constant.
	* cp-tree.h (fold_to_constant): Declare.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/new6.C: New test.
	* g++.dg/cpp2a/concepts-new1.C: New test.
parent 3843dc14
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment