This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] C++ part of -Wunused-but-set-{variable,parameter}
- From: Jason Merrill <jason at redhat dot com>
- To: Dodji Seketeli <dodji at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, jakub at redhat dot com
- Date: Mon, 03 May 2010 15:08:24 -0400
- Subject: Re: [RFC] C++ part of -Wunused-but-set-{variable,parameter}
- References: <20100503133728.GA29481@redhat.com>
On 05/03/2010 09:37 AM, Dodji Seketeli wrote:
I was not confortable with what to do with the call to mark_exp_read in
finish_expr_stmt, though. Depending on the context, the leaf expression
that ends up being marked can be an lvalue or an rvalue. Should I
introduce a another hook (say, mark_usage) that would walk the
expression like mark_exp_read does, and depending on the context, call
mark_[lr]_value_use?
I think using mark_exp_read is correct there, as the expression isn't
actually being used; we just mark it to avoid the warning. There should
be a comment to that effect, though.
Well, I suppose if we end up with a volatile lvalue gimplify_expr will
introduce an rvalue use, but I don't think the front end needs to worry
about that.
@@ -5228,6 +5231,11 @@ build_x_va_arg (tree expr, tree type)
if (expr == error_mark_node || !type)
return error_mark_node;
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ expr = mark_lvalue_use (expr);
+ else
+ expr = mark_rvalue_use (expr);
How the va_list argument to va_arg is used has nothing to do with the
type being passed. It's always used as an lvalue.
+
return build_va_arg (input_location, expr, type);
Extra blank line.
if (magic_varargs_p (fn))
- /* Do no conversions for magic varargs. */;
+ /* Do no conversions for magic varargs. */
+ if (TREE_CODE (TREE_TYPE (a)) == REFERENCE_TYPE)
+ a = mark_lvalue_use (a);
+ else
+ a = mark_rvalue_use (a);
else
a = convert_arg_to_ellipsis (a);
The magic varargs case should always use mark_type_use.
@@ -6258,6 +6271,13 @@ build_new_method_call (tree instance, tree fns, VEC(tree,gc) **args,
if (args != NULL)
make_args_non_dependent (*args);
}
+ else
+ {
+ if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
+ instance = mark_lvalue_use (instance);
+ else
+ instance = mark_rvalue_use (instance);
+ }
Do we really any marking here? build_new_method_call calls build_this
(instance), which calls cp_build_unary_op (ADDR_EXPR, which should do
the necessary marking.
@@ -327,6 +327,8 @@ build_typeid (tree exp)
if (processing_template_decl)
return build_min (TYPEID_EXPR, const_type_info_type_node, exp);
+ exp = mark_rvalue_use (exp);
This should be an lvalue use if (cond) (i.e. if we need to look in the
vtable), or a type use otherwise.
@@ -515,6 +517,8 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain)
/* Save casted types in the function's used types hash table. */
used_types_insert (type);
+ expr = mark_lvalue_use (expr);
This is an lvalue use for a cast to reference type, or an rvalue use for
a cast to pointer type.
@@ -4890,6 +4896,12 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
switch (TREE_CODE (expr))
{
+ case VAR_DECL:
+ case PARM_DECL:
+ mark_type_use (expr);
+ type = TREE_TYPE (expr);
+ break;
I don't think we want to split these out anymore.
@@ -4899,9 +4911,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
/* Fall through for fields that aren't bitfields. */
case FUNCTION_DECL:
- case VAR_DECL:
case CONST_DECL:
- case PARM_DECL:
case RESULT_DECL:
case TEMPLATE_PARM_INDEX:
type = TREE_TYPE (expr);
That is, put the cases back and put the mark_type_use here.
Jason