]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (create_array_type_for_decl): Only warn about invalid C++1y VLA if flag_iso...
authorJason Merrill <jason@redhat.com>
Fri, 7 Mar 2014 20:00:14 +0000 (15:00 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 7 Mar 2014 20:00:14 +0000 (15:00 -0500)
* 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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/init.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/ext/vla1.C
gcc/testsuite/g++.dg/ext/vla5.C
gcc/testsuite/g++.dg/ext/vla8.C
gcc/testsuite/g++.dg/init/new35.C
gcc/testsuite/g++.dg/init/new37.C

index fd0b4d2e240ec33ce6526c2bfb50a1e1600d55e8..988c3bf264f7b7c1f4e43a58a57a286afd375a47 100644 (file)
@@ -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
index 389ed1a9890d22b026b488e1648b5aecf390e35e..4eb3e69af7953086f45017100ead5eeef711b974 100644 (file)
@@ -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");
 
index 3ae2b5c619273d19c306f4bb581cd3334a4ebcd8..7f5d04539a5e5d0fd8f28f5dcc4806d4e03ff0b7 100644 (file)
@@ -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;
     }
index 8126905941e4a929ca951a416c7c795070b9c05c..6476d8aae56ef393e07ebf6d02bab387ad0e3376 100644 (file)
@@ -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
index d2c453fc658e6454850a4ceceb3f82e20ddfc518..b9c1271e3898ba0067859f5a252df4faea613477 100644 (file)
@@ -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,
index ae2e5038e18aa95b1b75e3211768a8f2c96e12a7..c91612c767548e2cd2d313bd0a3426b1900265b3 100644 (file)
@@ -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,
index f3725354fc3e607fbf284f549ecb1826b4ffc223..55ae5c8af0a310d96b6a4e4bad41efc5c0515c55 100644 (file)
@@ -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;
 }
index 2457e34f18336b7d81a52ed110ad5c8883a78f55..ca583091769f6da191d567f3e5fcf3e781781998 100644 (file)
@@ -6,5 +6,5 @@
 void
 test (int a)
 {
-  new (char[a]); // { dg-warning "variable-length array" }
+  new (char[a]); // { dg-warning "parentheses" }
 }
index 1c6000fa3b786b3aa0e1b9a1c76f1d7697c39e8d..9e2d6bdad436b284bcc34d0d8c6add56ba894f92 100644 (file)
@@ -8,7 +8,7 @@ struct AvlTreeIter
 
   AvlTreeIter()
   {
-    new (void* [Num()]); // { dg-warning "variable-length array" }
+    new (void* [Num()]); // { dg-warning "parentheses" }
   }
 };
 
index c5f79aa2f802949d17618467b693adb9f34870a3..7d07cf57f86594daf3812d832e186f3cfe2032f0 100644 (file)
@@ -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" }
index 82ca18b7aeba21b2d601dca32801f695cc1f8048..eab7854217454fd36127a578ee8391268412ffea 100644 (file)
@@ -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" }
 }