This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3 10/11] [PR gdb/14441] gdb: gdbtypes: add rvalue references to overloading resolution


On 03/04/2016 07:19 PM, Artemiy Volkov wrote:

> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index ce4b9be..c5b8ab5 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -3466,15 +3468,65 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
>  {
>    struct rank rank = {0,0};
>  
> -  if (types_equal (parm, arg))
> -    return EXACT_MATCH_BADNESS;
> -
>    /* Resolve typedefs */
>    if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
>      parm = check_typedef (parm);
>    if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
>      arg = check_typedef (arg);
>  
> +  if (value != NULL)
> +    {
> +      /* An rvalue argument cannot be bound to a non-const lvalue
> +         reference parameter...  */
> +      if (VALUE_LVAL (value) == not_lval
> +          && TYPE_CODE (parm) == TYPE_CODE_REF
> +          && !TYPE_CONST (parm->main_type->target_type))
> +        return INCOMPATIBLE_TYPE_BADNESS;
> +
> +      /* ... and an lvalue argument cannot be bound to an rvalue
> +         reference parameter.  [C++ 13.3.3.1.4p3]  */
> +      if (VALUE_LVAL (value) != not_lval
> +          && TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
> +        return INCOMPATIBLE_TYPE_BADNESS;
> +    }
> +
> +  if (types_equal (parm, arg))
> +    return EXACT_MATCH_BADNESS;
> +
> +  /* An lvalue reference to a function should get higher priority than an
> +     rvalue reference to a function. */
> +

Two spaces after "."

> +  if (value != NULL && TYPE_CODE (arg) == TYPE_CODE_RVALUE_REF
> +      && TYPE_CODE (TYPE_TARGET_TYPE (arg)) == TYPE_CODE_FUNC)
> +    {
> +      return (sum_ranks (rank_one_type (parm,
> +              lookup_pointer_type (TYPE_TARGET_TYPE (arg)), NULL),
> +              DIFFERENT_REFERENCE_TYPE_BADNESS));
> +    }
> +
> +  /* If a conversion to one type of reference is an identity conversion, and a
> +     conversion to the second type of reference is a non-identity conversion,
> +     choose the first type. */
> +

Same here.

> +  if (value != NULL && TYPE_IS_REFERENCE (parm) && TYPE_IS_REFERENCE (arg)
> +     && TYPE_CODE (parm) != TYPE_CODE (arg))
> +    {
> +      return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm),
> +              TYPE_TARGET_TYPE (arg), NULL), DIFFERENT_REFERENCE_TYPE_BADNESS));
> +    }
> +
> +  /* An rvalue should be first tried to bind to an rvalue reference, and then to
> +     an lvalue reference. */
> +

And here.

> +  if (value != NULL && TYPE_CODE (parm) == TYPE_CODE_REF
> +      && VALUE_LVAL (value) == not_lval)
> +    {
> +      if (TYPE_IS_REFERENCE (arg))
> +	arg = TYPE_TARGET_TYPE (arg);
> +      return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
> +			 LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS));
> +    }
> +
>    /* See through references, since we can almost make non-references
>       references.  */
>  
> 

Other than that, this looks good to me.

Keith


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]