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]

[C++ PATCH] template partial order tweek


Mark,
This patch tweeks my recent changing of template function partial ordering.
It appears that (a) I confused myself during the construction of that patch,
such that some of my comment description is no longer true, (b) Made the
treatment of a REFERENCE arg type too different from an lvalue arg expression.

This patch will order something like Foo ("a") with two templates,
#1      Foo (const T *), T = char
#2      Foo (const char (&)[I]), I = 2
the patch will select #2 as more specialized. for the partial ordering
we see if one template's PARM can be deduced as an ARG by the other template's
PARM. In this case the interesting one is whether `const char (&)[I]' can
be deduced by `const T *'. If the former was a real expression, it would be
because it would be decayed to a pointer `const char *'. This patch makes
that change (by simplifying the logic).

built & tested on i686-pc-linux-gnu, ok?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-02-08  Nathan Sidwell  <nathan@codesourcery.com>

	* pt.c (maybe_adjust_types_for_deduction, DEDUCE_ORDER case):
	Remove spurious information in comment. Allow further
	adjustments of REFERENCE_TYPE args.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.511
diff -c -3 -p -r1.511 pt.c
*** pt.c	2001/01/24 11:25:27	1.511
--- pt.c	2001/01/24 12:15:28
*************** maybe_adjust_types_for_deduction (strict
*** 7846,7876 ****
           compiler accepts it).
  
           John also confirms that deduction should proceed as in a function
!          call. Which implies the usual ARG and PARM bashing as DEDUCE_CALL.
           However, in ordering, ARG can have REFERENCE_TYPE, but no argument
           to an actual call can have such a type.
           
!          When deducing against a REFERENCE_TYPE, we can either not change
!          PARM's type, or we can change ARG's type too. The latter, though
!          seemingly more safe, turns out to give the following quirk. Consider
!          deducing a call to a `const int *' with the following template 
!          function parameters 
!            #1; T const *const &   ; T = int
!            #2; T *const &         ; T = const int
!            #3; T *                ; T = const int
!          It looks like #1 is the more specialized.  Taken pairwise, #1 is
!          more specialized than #2 and #2 is more specialized than #3, yet
!          there is no ordering between #1 and #3.
!          
!          So, if ARG is a reference, we look though it when PARM is
!          not a refence. When both are references we don't change either.  */
        if (TREE_CODE (*arg) == REFERENCE_TYPE)
          {
            if (TREE_CODE (*parm) == REFERENCE_TYPE)
              return 0;
            *arg = TREE_TYPE (*arg);
-           result |= UNIFY_ALLOW_OUTER_LESS_CV_QUAL;
-           goto skip_arg;
          }
        break;
      default:
--- 7846,7863 ----
           compiler accepts it).
  
           John also confirms that deduction should proceed as in a function
!          call. Which implies the usual ARG and PARM conversions as DEDUCE_CALL.
           However, in ordering, ARG can have REFERENCE_TYPE, but no argument
           to an actual call can have such a type.
           
!          If both ARG and PARM are REFERENCE_TYPE, we change neither.
!          If only ARG is a REFERENCE_TYPE, we look through that and then
!          proceed as with DEDUCE_CALL (which could further convert it).  */
        if (TREE_CODE (*arg) == REFERENCE_TYPE)
          {
            if (TREE_CODE (*parm) == REFERENCE_TYPE)
              return 0;
            *arg = TREE_TYPE (*arg);
          }
        break;
      default:
*************** maybe_adjust_types_for_deduction (strict
*** 7903,7909 ****
  	*arg = TYPE_MAIN_VARIANT (*arg);
      }
    
-   skip_arg:;
    /* [temp.deduct.call]
       
       If P is a cv-qualified type, the top level cv-qualifiers
--- 7890,7895 ----

template <typename T> int Foo (T const *) {return 1;}
template <unsigned I> int Foo (char const (&)[I]) {return 2;}

int main ()
{
  return Foo ("a") != 2;
}

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