summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2018-05-14 14:49:45 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2018-05-14 14:49:45 +0000
commit23cc4e77cce4041e4bd1a28d2161c72b50d0ede4 (patch)
treeeea7a98609a76102c16b62cf557dcee6cb9af004
parentb267855d7861e839aef9c28959171322f308f586 (diff)
* pt.c (tsubst) [ARRAY_TYPE]: Check valid_array_size_p.
(tsubst_copy_and_build) [NEW_EXPR]: Clear in_decl. gcc/c-family/ * c-common.c (valid_array_size_p): Add complain parameter. * c-common.h: ...which defaults to true. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260227 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-common.c13
-rw-r--r--gcc/c-family/c-common.h2
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/pt.c7
-rw-r--r--gcc/testsuite/g++.dg/init/new38.C6
-rw-r--r--gcc/testsuite/g++.dg/template/array30.C7
7 files changed, 36 insertions, 9 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index c38d5ecac898..27bdd2ddb1d0 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-09 Jason Merrill <jason@redhat.com>
+
+ * c-common.c (valid_array_size_p): Add complain parameter.
+ * c-common.h: ...which defaults to true.
+
2018-05-11 Jakub Jelinek <jakub@redhat.com>
PR c/85696
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index e8bb3eb23f8f..859eeb472529 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -7872,17 +7872,20 @@ reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
the name of the array, or NULL_TREE for unnamed arrays. */
bool
-valid_array_size_p (location_t loc, tree type, tree name)
+valid_array_size_p (location_t loc, tree type, tree name, bool complain)
{
if (type != error_mark_node
&& COMPLETE_TYPE_P (type)
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
&& !valid_constant_size_p (TYPE_SIZE_UNIT (type)))
{
- if (name)
- error_at (loc, "size of array %qE is too large", name);
- else
- error_at (loc, "size of unnamed array is too large");
+ if (complain)
+ {
+ if (name)
+ error_at (loc, "size of array %qE is too large", name);
+ else
+ error_at (loc, "size of unnamed array is too large");
+ }
return false;
}
return true;
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index f2c66628e533..c266fee74c70 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1248,7 +1248,7 @@ extern tree find_inv_trees (tree *, int *, void *);
extern tree replace_inv_trees (tree *, int *, void *);
extern bool reject_gcc_builtin (const_tree, location_t = UNKNOWN_LOCATION);
-extern bool valid_array_size_p (location_t, tree, tree);
+extern bool valid_array_size_p (location_t, tree, tree, bool = true);
/* In c-warn.c. */
extern void constant_expression_warning (tree);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 08cd81ffcee3..745059844bdf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-14 Jason Merrill <jason@redhat.com>
+
+ * pt.c (tsubst) [ARRAY_TYPE]: Check valid_array_size_p.
+ (tsubst_copy_and_build) [NEW_EXPR]: Clear in_decl.
+
2018-05-11 Jakub Jelinek <jakub@redhat.com>
PR c/85696
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 790d6ea25e9b..cd9011b1b61b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14788,6 +14788,10 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
r = build_cplus_array_type (type, domain);
+ if (!valid_array_size_p (input_location, r, in_decl,
+ (complain & tf_error)))
+ return error_mark_node;
+
if (TYPE_USER_ALIGN (t))
{
SET_TYPE_ALIGN (r, TYPE_ALIGN (t));
@@ -18147,6 +18151,9 @@ tsubst_copy_and_build (tree t,
}
}
+ /* Avoid passing an enclosing decl to valid_array_size_p. */
+ in_decl = NULL_TREE;
+
tree op1 = tsubst (TREE_OPERAND (t, 1), args, complain, in_decl);
tree op2 = RECUR (TREE_OPERAND (t, 2));
ret = build_new (&placement_vec, op1, op2, &init_vec,
diff --git a/gcc/testsuite/g++.dg/init/new38.C b/gcc/testsuite/g++.dg/init/new38.C
index 37da525bf781..a03e231cbfe9 100644
--- a/gcc/testsuite/g++.dg/init/new38.C
+++ b/gcc/testsuite/g++.dg/init/new38.C
@@ -22,7 +22,7 @@ template <typename T>
void
large_array_template1(int n)
{
- new T[n] // { dg-error "size of array is too large" }
+ new T[n] // { dg-error "size of unnamed array is too large" }
[(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
[1ULL << (sizeof(void *) * 4)];
}
@@ -31,7 +31,7 @@ template <typename T>
void
large_array_template2(int n)
{
- new T[n] // { dg-error "size of array is too large" }
+ new T[n] // { dg-error "size of unnamed array is too large" }
[(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
[1ULL << (sizeof(void *) * 4)];
}
@@ -40,7 +40,7 @@ template <typename T>
void
large_array_template3(int n)
{
- new T[n] // { dg-error "size of array is too large" }
+ new T[n] // { dg-error "size of unnamed array is too large" }
[(1ULL << (sizeof(void *) * 4)) / sizeof(T)]
[1ULL << (sizeof(void *) * 4)];
}
diff --git a/gcc/testsuite/g++.dg/template/array30.C b/gcc/testsuite/g++.dg/template/array30.C
new file mode 100644
index 000000000000..3608c2e12337
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array30.C
@@ -0,0 +1,7 @@
+template <int I>
+struct A
+{
+ int ar[I][I][I][I][I][I][I][I][I][I]; // { dg-error "too large" }
+};
+
+A<66000> a;