Class template argument deduction in new-expression
[gcc.git] / gcc / cp / init.c
index 99eeb8a893f0442592b12c831de4d6171e017b2d..191fe13e31039947d1d5d660eef0b9c0d8d9ba94 100644 (file)
@@ -1217,6 +1217,12 @@ emit_mem_initializers (tree mem_inits)
        /* C++14 DR1658 Means we do not have to construct vbases of
           abstract classes.  */
        construct_virtual_base (subobject, arguments);
+      else
+       /* When not constructing vbases of abstract classes, at least mark
+          the arguments expressions as read to avoid
+          -Wunused-but-set-parameter false positives.  */
+       for (tree arg = arguments; arg; arg = TREE_CHAIN (arg))
+         mark_exp_read (TREE_VALUE (arg));
 
       if (inherited_base)
        pop_deferring_access_checks ();
@@ -2811,8 +2817,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
        {
          pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
                   typedef_variant_p (orig_type)
-                  ? "non-constant array new length must be specified "
-                    "directly, not by typedef"
+                  ? G_("non-constant array new length must be specified "
+                       "directly, not by typedef")
                   : G_("non-constant array new length must be specified "
                        "without parentheses around the type-id"));
        }
@@ -3472,15 +3478,19 @@ build_new (vec<tree, va_gc> **placement, tree type, tree nelts,
   if (type == error_mark_node)
     return error_mark_node;
 
-  if (nelts == NULL_TREE && vec_safe_length (*init) == 1
+  if (nelts == NULL_TREE
       /* Don't do auto deduction where it might affect mangling.  */
       && (!processing_template_decl || at_function_scope_p ()))
     {
       tree auto_node = type_uses_auto (type);
       if (auto_node)
        {
-         tree d_init = (**init)[0];
-         d_init = resolve_nondeduced_context (d_init, complain);
+         tree d_init = NULL_TREE;
+         if (vec_safe_length (*init) == 1)
+           {
+             d_init = (**init)[0];
+             d_init = resolve_nondeduced_context (d_init, complain);
+           }
          type = do_auto_deduction (type, d_init, auto_node);
        }
     }