Commit b75bf8b1 by Jason Merrill Committed by Jason Merrill

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
parent c12b3bd3
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> 2014-03-07 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58609 PR c++/58609
......
...@@ -8530,7 +8530,8 @@ create_array_type_for_decl (tree name, tree type, tree size) ...@@ -8530,7 +8530,8 @@ create_array_type_for_decl (tree name, tree type, tree size)
return error_mark_node; 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"); pedwarn (input_location, OPT_Wvla, "array of array of runtime bound");
/* Figure out the index type for the array. */ /* Figure out the index type for the array. */
...@@ -9762,7 +9763,8 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -9762,7 +9763,8 @@ grokdeclarator (const cp_declarator *declarator,
: G_("cannot declare pointer to qualified function type %qT"), : G_("cannot declare pointer to qualified function type %qT"),
type); 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, pedwarn (input_location, OPT_Wvla,
declarator->kind == cdk_reference declarator->kind == cdk_reference
? G_("reference to array of runtime bound") ? G_("reference to array of runtime bound")
...@@ -10110,7 +10112,8 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -10110,7 +10112,8 @@ grokdeclarator (const cp_declarator *declarator,
type = error_mark_node; 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, pedwarn (input_location, OPT_Wvla,
"typedef naming array of runtime bound"); "typedef naming array of runtime bound");
......
...@@ -2285,6 +2285,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, ...@@ -2285,6 +2285,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
is therefore reusable. */ is therefore reusable. */
tree data_addr; tree data_addr;
tree init_preeval_expr = NULL_TREE; tree init_preeval_expr = NULL_TREE;
tree orig_type = type;
if (nelts) if (nelts)
{ {
...@@ -2330,7 +2331,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, ...@@ -2330,7 +2331,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
if (complain & tf_error) if (complain & tf_error)
{ {
error_at (EXPR_LOC_OR_LOC (inner_nelts, input_location), 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); cxx_constant_value(inner_nelts);
} }
nelts = error_mark_node; nelts = error_mark_node;
...@@ -2344,7 +2345,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, ...@@ -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)) 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; return error_mark_node;
} }
...@@ -2357,8 +2358,17 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, ...@@ -2357,8 +2358,17 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
&& !TREE_CONSTANT (maybe_constant_value (outer_nelts))) && !TREE_CONSTANT (maybe_constant_value (outer_nelts)))
{ {
if (complain & tf_warning_or_error) 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 else
return error_mark_node; return error_mark_node;
} }
......
...@@ -11954,7 +11954,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) ...@@ -11954,7 +11954,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (cxx_dialect >= cxx1y if (cxx_dialect >= cxx1y
&& !(TREE_CODE (t) == REFERENCE_TYPE && REFERENCE_VLA_OK (t)) && !(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) if (complain & tf_warning_or_error)
pedwarn pedwarn
......
...@@ -7031,7 +7031,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, ...@@ -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) if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla, pedwarn (input_location, OPT_Wvla,
......
...@@ -1552,7 +1552,8 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain) ...@@ -1552,7 +1552,8 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
return value; 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) if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla, pedwarn (input_location, OPT_Wvla,
...@@ -5471,7 +5472,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) ...@@ -5471,7 +5472,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
if (argtype != error_mark_node) 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) if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla, pedwarn (input_location, OPT_Wvla,
......
...@@ -9,7 +9,7 @@ class A { A (int); }; ...@@ -9,7 +9,7 @@ class A { A (int); };
A::A (int i) A::A (int i)
{ {
int ar[1][i]; // { dg-error "variable length array" } int ar[1][i]; // { dg-error "array" }
ar[0][0] = 0; ar[0][0] = 0;
} }
......
...@@ -6,5 +6,5 @@ ...@@ -6,5 +6,5 @@
void void
test (int a) test (int a)
{ {
new (char[a]); // { dg-warning "variable-length array" } new (char[a]); // { dg-warning "parentheses" }
} }
...@@ -8,7 +8,7 @@ struct AvlTreeIter ...@@ -8,7 +8,7 @@ struct AvlTreeIter
AvlTreeIter() AvlTreeIter()
{ {
new (void* [Num()]); // { dg-warning "variable-length array" } new (void* [Num()]); // { dg-warning "parentheses" }
} }
}; };
......
...@@ -5,7 +5,7 @@ int ...@@ -5,7 +5,7 @@ int
main (int argc, char **argv) main (int argc, char **argv)
{ {
typedef char A[argc]; 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[0]; // { dg-error "must be constant|not a constant" }
new A[5]; // { 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" } new (A[0]); // { dg-error "must be constant|not a constant" }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
void void
nonconst(int n) 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" } new long[n][n]; // { dg-error "variable length|array size|not a constant" }
} }
......
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