aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-03-07 15:00:14 -0500
committerJason Merrill <jason@gcc.gnu.org>2014-03-07 15:00:14 -0500
commitb75bf8b188f71f129f1b97da93e3246637c384e8 (patch)
tree7eb9de0c86e9f4c54e5cd212d59aa19b658e8b0b
parentc12b3bd34db27979bc1ce2015f09c959cb9a5fb2 (diff)
downloadgcc-b75bf8b188f71f129f1b97da93e3246637c384e8.zip
gcc-b75bf8b188f71f129f1b97da93e3246637c384e8.tar.gz
gcc-b75bf8b188f71f129f1b97da93e3246637c384e8.tar.bz2
decl.c (create_array_type_for_decl): Only warn about invalid C++1y VLA if flag_iso or warn_vla>0.
* decl.c (create_array_type_for_decl): Only warn about invalid C++1y VLA if flag_iso or warn_vla>0. (grokdeclarator): Likewise. * pt.c (tsubst): Likewise. * semantics.c (finish_decltype_type): Likewise. * typeck.c (cxx_sizeof_or_alignof_type): Likewise. (cp_build_addr_expr_1): Likewise. * init.c (build_new_1): Improve diagnostics. From-SVN: r208411
-rw-r--r--gcc/cp/ChangeLog11
-rw-r--r--gcc/cp/decl.c9
-rw-r--r--gcc/cp/init.c18
-rw-r--r--gcc/cp/pt.c3
-rw-r--r--gcc/cp/semantics.c3
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/g++.dg/ext/vla1.C2
-rw-r--r--gcc/testsuite/g++.dg/ext/vla5.C2
-rw-r--r--gcc/testsuite/g++.dg/ext/vla8.C2
-rw-r--r--gcc/testsuite/g++.dg/init/new35.C2
-rw-r--r--gcc/testsuite/g++.dg/init/new37.C2
11 files changed, 44 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fd0b4d2..988c3bf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,14 @@
+2014-03-07 Jason Merrill <jason@redhat.com>
+
+ * decl.c (create_array_type_for_decl): Only warn about invalid
+ C++1y VLA if flag_iso or warn_vla>0.
+ (grokdeclarator): Likewise.
+ * pt.c (tsubst): Likewise.
+ * semantics.c (finish_decltype_type): Likewise.
+ * typeck.c (cxx_sizeof_or_alignof_type): Likewise.
+ (cp_build_addr_expr_1): Likewise.
+ * init.c (build_new_1): Improve diagnostics.
+
2014-03-07 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58609
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 389ed1a..4eb3e69 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8530,7 +8530,8 @@ create_array_type_for_decl (tree name, tree type, tree size)
return error_mark_node;
}
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla, "array of array of runtime bound");
/* Figure out the index type for the array. */
@@ -9762,7 +9763,8 @@ grokdeclarator (const cp_declarator *declarator,
: G_("cannot declare pointer to qualified function type %qT"),
type);
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla,
declarator->kind == cdk_reference
? G_("reference to array of runtime bound")
@@ -10110,7 +10112,8 @@ grokdeclarator (const cp_declarator *declarator,
type = error_mark_node;
}
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla,
"typedef naming array of runtime bound");
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3ae2b5c..7f5d045 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2285,6 +2285,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
is therefore reusable. */
tree data_addr;
tree init_preeval_expr = NULL_TREE;
+ tree orig_type = type;
if (nelts)
{
@@ -2330,7 +2331,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
if (complain & tf_error)
{
error_at (EXPR_LOC_OR_LOC (inner_nelts, input_location),
- "array size in operator new must be constant");
+ "array size in new-expression must be constant");
cxx_constant_value(inner_nelts);
}
nelts = error_mark_node;
@@ -2344,7 +2345,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
if (variably_modified_type_p (elt_type, NULL_TREE) && (complain & tf_error))
{
- error ("variably modified type not allowed in operator new");
+ error ("variably modified type not allowed in new-expression");
return error_mark_node;
}
@@ -2357,8 +2358,17 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
&& !TREE_CONSTANT (maybe_constant_value (outer_nelts)))
{
if (complain & tf_warning_or_error)
- pedwarn(EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
- "ISO C++ does not support variable-length array types");
+ {
+ const char *msg;
+ if (typedef_variant_p (orig_type))
+ msg = ("non-constant array new length must be specified "
+ "directly, not by typedef");
+ else
+ msg = ("non-constant array new length must be specified "
+ "without parentheses around the type-id");
+ pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location),
+ OPT_Wvla, msg);
+ }
else
return error_mark_node;
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 8126905..6476d8a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11954,7 +11954,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (cxx_dialect >= cxx1y
&& !(TREE_CODE (t) == REFERENCE_TYPE && REFERENCE_VLA_OK (t))
- && array_of_runtime_bound_p (type))
+ && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index d2c453f..b9c1271 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7031,7 +7031,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
}
}
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla,
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ae2e503..c91612c 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1552,7 +1552,8 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
return value;
}
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
+ && (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla,
@@ -5471,7 +5472,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
if (argtype != error_mark_node)
{
- if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (argtype))
+ if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (argtype)
+ && (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla,
diff --git a/gcc/testsuite/g++.dg/ext/vla1.C b/gcc/testsuite/g++.dg/ext/vla1.C
index f372535..55ae5c8 100644
--- a/gcc/testsuite/g++.dg/ext/vla1.C
+++ b/gcc/testsuite/g++.dg/ext/vla1.C
@@ -9,7 +9,7 @@ class A { A (int); };
A::A (int i)
{
- int ar[1][i]; // { dg-error "variable length array" }
+ int ar[1][i]; // { dg-error "array" }
ar[0][0] = 0;
}
diff --git a/gcc/testsuite/g++.dg/ext/vla5.C b/gcc/testsuite/g++.dg/ext/vla5.C
index 2457e34..ca58309 100644
--- a/gcc/testsuite/g++.dg/ext/vla5.C
+++ b/gcc/testsuite/g++.dg/ext/vla5.C
@@ -6,5 +6,5 @@
void
test (int a)
{
- new (char[a]); // { dg-warning "variable-length array" }
+ new (char[a]); // { dg-warning "parentheses" }
}
diff --git a/gcc/testsuite/g++.dg/ext/vla8.C b/gcc/testsuite/g++.dg/ext/vla8.C
index 1c6000f..9e2d6bd 100644
--- a/gcc/testsuite/g++.dg/ext/vla8.C
+++ b/gcc/testsuite/g++.dg/ext/vla8.C
@@ -8,7 +8,7 @@ struct AvlTreeIter
AvlTreeIter()
{
- new (void* [Num()]); // { dg-warning "variable-length array" }
+ new (void* [Num()]); // { dg-warning "parentheses" }
}
};
diff --git a/gcc/testsuite/g++.dg/init/new35.C b/gcc/testsuite/g++.dg/init/new35.C
index c5f79aa..7d07cf5 100644
--- a/gcc/testsuite/g++.dg/init/new35.C
+++ b/gcc/testsuite/g++.dg/init/new35.C
@@ -5,7 +5,7 @@ int
main (int argc, char **argv)
{
typedef char A[argc];
- new A; // { dg-warning "variable-length array types|not a constant" }
+ new A; // { dg-warning "array" }
new A[0]; // { dg-error "must be constant|not a constant" }
new A[5]; // { dg-error "must be constant|not a constant" }
new (A[0]); // { dg-error "must be constant|not a constant" }
diff --git a/gcc/testsuite/g++.dg/init/new37.C b/gcc/testsuite/g++.dg/init/new37.C
index 82ca18b..eab7854 100644
--- a/gcc/testsuite/g++.dg/init/new37.C
+++ b/gcc/testsuite/g++.dg/init/new37.C
@@ -3,7 +3,7 @@
void
nonconst(int n)
{
- new (long[n][n]); // { dg-error "variable length|array size|not a constant" }
+ new (long[n][n]); // { dg-error "variable length|array size|not a constant|runtime bound" }
new long[n][n]; // { dg-error "variable length|array size|not a constant" }
}