c++/8640: [2003-01-22] template specialization bug #2 (gcc3.2)

lerdsuwa@gcc.gnu.org lerdsuwa@gcc.gnu.org
Sun Mar 16 13:56:00 GMT 2003


Synopsis: [2003-01-22] template specialization bug #2 (gcc3.2)

State-Changed-From-To: analyzed->closed
State-Changed-By: lerdsuwa
State-Changed-When: Sun Mar 16 12:45:09 2003
State-Changed-Why:
    Not a bug.  It's the way partial ordering works.  
    To see how this works, consider a simpler example:
    
      template<typename T> void foo (T t); // #1
      template<typename U> void foo (X<U> x); // #2
    
    To find out which one is more specialized, you substitute
    function argument into another function parameter and
    try to deduce template parameter.  
    
    First, take a 't' of type 'T' from foo #1 and substitute
    into foo #2 'u' parameter of type 'X<U>' like this.  
    
      foo<U>(X<U> t); // #2, where t of is any type T
    
    You find that 't' can be any type, not necessary an 
    instantiation of class template X.  So deduction 
    of 'U' fails.  Here #1 is not more specialized than #2.
    
    On the other hand, take a 'u' of type 'X<U>' from foo #2 
    and put into foo #1:
    
      foo<T>(T x); // #1, where x of is any type X<U>
    
    You can duduce T = X<U> here.  So the deduction succeeds.
    And #2 is more specialized than #1.
    
    Deciding which specialization to use is based on the above
    algorithm (which is specified in the C++ standard).  If
    one deduction fails, and another passes, we pick the more
    specialized one.  However with your code:
    
        template<int shift1, typename T> void foo (T x);
        template<int shift2, typename T> void foo (X<U> x);
    
    'shift1' and 'shift2' cannot be deduced by the above
    method, none is more specialized than the other.  And
    both are considered during a function call.
    
    If you don't like how it works, comp.std.c++ newsgroup
    is the place to discuss about the behavior.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8640



More information about the Gcc-bugs mailing list