Hi again,

On 04/15/2015 03:31 AM, Jason Merrill wrote:
There are various places in the compiler that error and continue if tf_error is set, but return error_mark_node immediately if not; it seems reasonable to follow that pattern in the places that don't currently check the return value.
Thus I tested the below. Ok for trunk?

Thanks,
Paolo.

///////////////////
2015-04-16  Paolo Carlini  <paolo.carl...@oracle.com>

        * call.c (build_op_delete_call, build_over_call): Check mark_used
        return value.
        * class.c (resolve_address_of_overloaded_function): Likewise.
        * decl.c (cxx_maybe_build_cleanup): Likewise.
        * pt.c (gen_elem_of_pack_expansion_instantiation, tsubst_baselink,
        tsubst_qualified_id, tsubst_copy, tsubst_copy_and_build): Likewise.
        * rtti.c (build_dynamic_cast_1): Likewise.
        * semantics.c (process_outer_var_ref): Likewise.
        * typeck.c (build_class_member_access_expr,
        cp_build_function_call_vec, cp_build_addr_expr_1): Likewise.
Index: call.c
===================================================================
--- call.c      (revision 222143)
+++ call.c      (working copy)
@@ -5968,7 +5968,8 @@ build_op_delete_call (enum tree_code code, tree ad
          argarray[0] = addr;
          for (i = 1; i < nargs; i++)
            argarray[i] = CALL_EXPR_ARG (placement, i);
-         mark_used (fn);
+         if (!mark_used (fn, complain) && !(complain & tf_error))
+           return error_mark_node;
          return build_cxx_call (fn, nargs, argarray, complain);
        }
       else
@@ -7400,7 +7401,8 @@ build_over_call (struct z_candidate *cand, int fla
         the implementation elided its use.  */
       if (!trivial || DECL_DELETED_FN (fn))
        {
-         mark_used (fn);
+         if (!mark_used (fn, complain) && !(complain & tf_error))
+           return error_mark_node;
          already_used = true;
        }
 
Index: class.c
===================================================================
--- class.c     (revision 222143)
+++ class.c     (working copy)
@@ -7755,8 +7755,8 @@ resolve_address_of_overloaded_function (tree targe
       /* Make =delete work with SFINAE.  */
       if (DECL_DELETED_FN (fn) && !(flags & tf_error))
        return error_mark_node;
-      
-      mark_used (fn);
+      if (!mark_used (fn, flags) && !(flags & tf_error))
+       return error_mark_node;
     }
 
   /* We could not check access to member functions when this
Index: decl.c
===================================================================
--- decl.c      (revision 222143)
+++ decl.c      (working copy)
@@ -14587,7 +14587,8 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t
         ordinary FUNCTION_DECL.  */
       fn = lookup_name (id);
       arg = build_address (decl);
-      mark_used (decl);
+      if (!mark_used (decl, complain) && !(complain & tf_error))
+       return error_mark_node;
       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
       if (cleanup == error_mark_node)
        return error_mark_node;
@@ -14627,10 +14628,11 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t
     SET_EXPR_LOCATION (cleanup, UNKNOWN_LOCATION);
 
   if (cleanup
-      && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
-    /* Treat objects with destructors as used; the destructor may do
-       something substantive.  */
-    mark_used (decl);
+      && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
+      /* Treat objects with destructors as used; the destructor may do
+        something substantive.  */
+      && !mark_used (decl, complain) && !(complain & tf_error))
+    return error_mark_node;
 
   return cleanup;
 }
Index: pt.c
===================================================================
--- pt.c        (revision 222143)
+++ pt.c        (working copy)
@@ -9833,7 +9833,8 @@ gen_elem_of_pack_expansion_instantiation (tree pat
          if (index == 0)
            {
              aps = make_argument_pack_select (arg_pack, index);
-             mark_used (parm);
+             if (!mark_used (parm, complain) && !(complain & tf_error))
+               return error_mark_node;
              register_local_specialization (aps, parm);
            }
          else
@@ -12603,8 +12604,9 @@ tsubst_baselink (tree baselink, tree object_type,
        point.)  */
     if (BASELINK_P (baselink))
       fns = BASELINK_FUNCTIONS (baselink);
-    if (!template_id_p && !really_overloaded_fn (fns))
-      mark_used (OVL_CURRENT (fns));
+    if (!template_id_p && !really_overloaded_fn (fns)
+       && !mark_used (OVL_CURRENT (fns), complain) && !(complain & tf_error))
+      return error_mark_node;
 
     /* Add back the template arguments, if present.  */
     if (BASELINK_P (baselink) && template_id_p)
@@ -12719,7 +12721,8 @@ tsubst_qualified_id (tree qualified_id, tree args,
       check_accessibility_of_qualified_id (expr, /*object_type=*/NULL_TREE,
                                           scope);
       /* Remember that there was a reference to this entity.  */
-      mark_used (expr);
+      if (!mark_used (expr, complain) && !(complain & tf_error))
+       return error_mark_node;
     }
 
   if (expr == error_mark_node || TREE_CODE (expr) == TREE_LIST)
@@ -12829,7 +12832,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com
       
       if (TREE_CODE (r) == ARGUMENT_PACK_SELECT)
        r = ARGUMENT_PACK_SELECT_ARG (r);
-      mark_used (r);
+      if (!mark_used (r, complain) && !(complain & tf_error))
+       return error_mark_node;
       return r;
 
     case CONST_DECL:
@@ -12986,7 +12990,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com
        }
       else
        r = t;
-      mark_used (r);
+      if (!mark_used (r, complain) && !(complain & tf_error))
+       return error_mark_node;
       return r;
 
     case NAMESPACE_DECL:
@@ -13350,7 +13355,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com
        tree op1 = tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl);
        r = build2 (code, type, op0, op1);
        PTRMEM_OK_P (r) = PTRMEM_OK_P (t);
-       mark_used (TREE_OPERAND (r, 1));
+       if (!mark_used (TREE_OPERAND (r, 1), complain)
+           && !(complain & tf_error))
+         return error_mark_node;
        return r;
       }
 
@@ -14868,8 +14875,9 @@ tsubst_copy_and_build (tree t,
       op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
                                                args, complain, in_decl);
       /* Remember that there was a reference to this entity.  */
-      if (DECL_P (op1))
-       mark_used (op1);
+      if (DECL_P (op1)
+         && !mark_used (op1, complain) && !(complain & tf_error))
+       RETURN (error_mark_node);
       RETURN (build_x_arrow (input_location, op1, complain));
 
     case NEW_EXPR:
@@ -15120,8 +15128,9 @@ tsubst_copy_and_build (tree t,
          }
 
        /* Remember that there was a reference to this entity.  */
-       if (DECL_P (function))
-         mark_used (function, complain);
+       if (DECL_P (function)
+           && !mark_used (function, complain) && !(complain & tf_error))
+         RETURN (error_mark_node);
 
        /* Put back tf_decltype for the actual call.  */
        complain |= decltype_flag;
@@ -15304,8 +15313,9 @@ tsubst_copy_and_build (tree t,
        object = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
                                                     args, complain, in_decl);
        /* Remember that there was a reference to this entity.  */
-       if (DECL_P (object))
-         mark_used (object);
+       if (DECL_P (object)
+           && !mark_used (object, complain) && !(complain & tf_error))
+         RETURN (error_mark_node);
        object_type = TREE_TYPE (object);
 
        member = TREE_OPERAND (t, 1);
Index: rtti.c
===================================================================
--- rtti.c      (revision 222143)
+++ rtti.c      (working copy)
@@ -708,10 +708,12 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst
          target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
          static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
          td2 = get_tinfo_decl (target_type);
-         mark_used (td2);
+         if (!mark_used (td2, complain) && !(complain & tf_error))
+           return error_mark_node;
          td2 = cp_build_addr_expr (td2, complain);
          td3 = get_tinfo_decl (static_type);
-         mark_used (td3);
+         if (!mark_used (td3, complain) && !(complain & tf_error))
+           return error_mark_node;
          td3 = cp_build_addr_expr (td3, complain);
 
          /* Determine how T and V are related.  */
Index: semantics.c
===================================================================
--- semantics.c (revision 222143)
+++ semantics.c (working copy)
@@ -3117,7 +3117,8 @@ process_outer_var_ref (tree decl, tsubst_flags_t c
   tree initializer = convert_from_reference (decl);
 
   /* Mark it as used now even if the use is ill-formed.  */
-  mark_used (decl);
+  if (!mark_used (decl, complain) && !(complain & tf_error))
+    return error_mark_node;
 
   /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
      support for an approach in which a reference to a local
Index: typeck.c
===================================================================
--- typeck.c    (revision 222143)
+++ typeck.c    (working copy)
@@ -2298,7 +2298,8 @@ build_class_member_access_expr (tree object, tree
   if (DECL_P (member))
     {
       member_scope = DECL_CLASS_CONTEXT (member);
-      mark_used (member);
+      if (!mark_used (member, complain) && !(complain & tf_error))
+       return error_mark_node;
       if (TREE_DEPRECATED (member))
        warn_deprecated_use (member, NULL_TREE);
     }
@@ -3477,7 +3478,8 @@ cp_build_function_call_vec (tree function, vec<tre
 
   if (TREE_CODE (function) == FUNCTION_DECL)
     {
-      mark_used (function);
+      if (!mark_used (function, complain) && !(complain & tf_error))
+       return error_mark_node;
       fndecl = function;
 
       /* Convert anything with function type to a pointer-to-function.  */
@@ -5376,7 +5378,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue
         and the created OFFSET_REF.  */
       tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
       tree fn = get_first_fn (TREE_OPERAND (arg, 1));
-      mark_used (fn);
+      if (!mark_used (fn, complain) && !(complain & tf_error))
+       return error_mark_node;
 
       if (! flag_ms_extensions)
        {
@@ -5563,7 +5566,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue
         function.  */
       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
                  && DECL_STATIC_FUNCTION_P (fn));
-      mark_used (fn);
+      if (!mark_used (fn, complain) && !(complain & tf_error))
+       return error_mark_node;
       val = build_address (fn);
       if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
        /* Do not lose object's side effects.  */

Reply via email to