This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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] Fix PR c++/26698: g++ accepts const-incorrect code due to conversion function


Simon Martin wrote:
> Hi all.

> The attached patch modifies build_user_type_conversion_1 so that
> conversion operators are not considered when they should not according
> to the standard.

This looks good.  Minor note:

> Index: gcc/cp/call.c
> ===================================================================
> --- gcc/cp/call.c	(revision 129069)
> +++ gcc/cp/call.c	(working copy)
> @@ -2601,7 +2601,22 @@ build_user_type_conversion_1 (tree totyp
>      ctors = lookup_fnfields (totype, complete_ctor_identifier, 0);
>  
>    if (IS_AGGR_TYPE (fromtype))
> -    conv_fns = lookup_conversions (fromtype);
> +    {
> +      tree to_main = TYPE_MAIN_VARIANT (non_reference (totype));
> +      tree from_main = TYPE_MAIN_VARIANT (fromtype);
> +      if (same_type_p (to_main, from_main) ||
> +	  (CLASS_TYPE_P (to_main) && CLASS_TYPE_P (from_main)
> +	   && DERIVED_FROM_P (to_main, from_main)))

You can simplify this condition a bit.  If you use
same_type_ignoring_top_level_qualifiers_p, it will automatically do the
TYPE_MAIN_VARIANT bit for you.  And, so will DERIVED_FROM_P, so:

  tree to_non_ref = non_reference (totype);
  if (same_type_ignoring_top_level_qualifiers_p (to_non_ref, fromtype)
      || (CLASS_TYPE_P (to_non_ref) && CLASS_TYPE_P (fromtype)
          && DERIVED_FROM_P (to_non_ref, fromtype))

should work.  OK with that change.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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