Commit 80fdaad1 by Jason Merrill Committed by Jason Merrill

PR c++/80227 - SFINAE and negative array size.

	* decl.c (compute_array_index_type): Use
	build_converted_constant_expr and valid_constant_size_p.

From-SVN: r258604
parent 929a0122
2018-03-16 Jason Merrill <jason@redhat.com>
PR c++/80227 - SFINAE and negative array size.
* decl.c (compute_array_index_type): Use
build_converted_constant_expr and valid_constant_size_p.
PR c++/84906 - silent wrong code with ambiguous conversion.
* call.c (build_user_type_conversion_1): Set need_temporary_p on
ambiguous conversion.
......
......@@ -9514,8 +9514,6 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
if (!type_dependent_expression_p (size))
{
tree type = TREE_TYPE (size);
size = mark_rvalue_use (size);
if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
......@@ -9525,29 +9523,8 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
else
{
size = instantiate_non_dependent_expr_sfinae (size, complain);
if (CLASS_TYPE_P (type)
&& CLASSTYPE_LITERAL_P (type))
{
size = build_expr_type_conversion (WANT_INT, size, true);
if (!size)
{
if (!(complain & tf_error))
return error_mark_node;
if (name)
error ("size of array %qD has non-integral type %qT",
name, type);
else
error ("size of array has non-integral type %qT", type);
size = integer_one_node;
}
if (size == error_mark_node)
return error_mark_node;
type = TREE_TYPE (size);
}
if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
size = maybe_constant_value (size);
size = build_converted_constant_expr (size_type_node, size, complain);
size = maybe_constant_value (size);
if (!TREE_CONSTANT (size))
size = osize;
......@@ -9557,6 +9534,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
return error_mark_node;
/* The array bound must be an integer type. */
tree type = TREE_TYPE (size);
if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
{
if (!(complain & tf_error))
......@@ -9566,7 +9544,6 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
else
error ("size of array has non-integral type %qT", type);
size = integer_one_node;
type = TREE_TYPE (size);
}
}
......@@ -9604,15 +9581,12 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
/* Normally, the array-bound will be a constant. */
if (TREE_CODE (size) == INTEGER_CST)
{
/* Check to see if the array bound overflowed. Make that an
error, no matter how generous we're being. */
constant_expression_error (size);
/* An array must have a positive number of elements. */
if (tree_int_cst_lt (size, integer_zero_node))
if (!valid_constant_size_p (size))
{
if (!(complain & tf_error))
return error_mark_node;
if (name)
error ("size of array %qD is negative", name);
else
......
// PR c++/80227
// { dg-do compile { target c++11 } }
template <class T>
int foo (T);
template <class T, class U = T [sizeof (T) - 5]>
int foo (T, U* = 0);
int i = foo (123);
......@@ -5,7 +5,7 @@
void
foo (float n)
{
int A[n][n]; // { dg-error "has non-integral type" }
int A[n][n]; // { dg-error "has non-integral type|converted constant expression" }
#pragma omp parallel private(A)
;
}
......@@ -32,7 +32,7 @@ template <typename T>
void *
callnew_fail_3()
{
return new T[2][T::n]; // { dg-error "size of array has non-integral type" }
return new T[2][T::n]; // { dg-error "size of array has non-integral type|converted constant expression" }
}
struct T1 {
......
......@@ -2,5 +2,4 @@
/* { dg-do compile } */
/* { dg-options "-fsanitize=undefined" } */
int a[(long) 4e20]; /* { dg-error "overflow in constant expression" } */
/* { dg-error "size of array .a. is too large" "" { target *-*-* } .-1 } */
int a[(long) 4e20]; /* { dg-error "size of array .a. is (too large|negative)" } */
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