+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
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. */
: 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")
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");
is therefore reusable. */
tree data_addr;
tree init_preeval_expr = NULL_TREE;
+ tree orig_type = type;
if (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;
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;
}
&& !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;
}
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
}
}
- 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,
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,
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,
A::A (int i)
{
- int ar[1][i]; // { dg-error "variable length array" }
+ int ar[1][i]; // { dg-error "array" }
ar[0][0] = 0;
}
void
test (int a)
{
- new (char[a]); // { dg-warning "variable-length array" }
+ new (char[a]); // { dg-warning "parentheses" }
}
AvlTreeIter()
{
- new (void* [Num()]); // { dg-warning "variable-length array" }
+ new (void* [Num()]); // { dg-warning "parentheses" }
}
};
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" }
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" }
}