www.digitalmars.com         C & C++   DMDScript  

c++ - [bug] partial ordering of templates

reply Christof Meerwald <cmeerw web.de> writes:
DMC 8.42.5 compiles the following program without any errors, but the
template instantiation really should be ambiguous:

template<int n, int m>
struct D {
  static const int val = 0;
};

template<int n>
struct D<n, n> {
  static const int val = 1;
};

template<int n>
struct D<1, n> {
  static const int val = 2;
};

int main()
{
  return D<1, 1>::val;
}


bye, Christof

-- 
http://cmeerw.org
mailto:cmeerw at web.de                       xmpp:cmeerw at cmeerw.org

...and what have you contributed to the Net?
Mar 28 2005
parent reply "Walter" <newshound digitalmars.com> writes:
I don't think it should be ambiguous. Both D<n,n> and D<1,n> match, and the
partial specialization rules say that the one that is most specialized wins.
D<1,n> is most specialized.
Apr 20 2005
parent reply Christof Meerwald <cmeerw web.de> writes:
Walter wrote:
 I don't think it should be ambiguous. Both D<n,n> and D<1,n> match, and the
 partial specialization rules say that the one that is most specialized wins.
 D<1,n> is most specialized.

But, D<1,n> isn't more specialized than D<n,n>. If I remember correctly, you have to synthesize a unique constant for non-type template arguments and then try to deduce the template arguments of the other specialization. But in that case, argument deduction will fail, because the synthesized constant isn't equal to 1. bye, Christof
Apr 20 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Christof Meerwald" <cmeerw web.de> wrote in message
news:d45go5$31b3$1 digitaldaemon.com...
 Walter wrote:
 I don't think it should be ambiguous. Both D<n,n> and D<1,n> match, and


 partial specialization rules say that the one that is most specialized


 D<1,n> is most specialized.

But, D<1,n> isn't more specialized than D<n,n>. If I remember correctly, you have to synthesize a unique constant for non-type template arguments and then try to deduce the template arguments of the other specialization. But in that case, argument deduction will fail, because the synthesized constant isn't equal to 1.

Darn it, I think you're right <g>.
Apr 20 2005
parent Christof Meerwald <cmeerw web.de> writes:
Walter wrote:
 Darn it, I think you're right <g>.

I am afraid, there is still one more problem in 8.43.6n: template<int n, int m> struct A { }; template<int n> struct A<n, n> { }; template<int n> struct A<1, n> { }; template<> struct A<1, 1> { }; int main() { A<1, 1> a; // Error: ambiguous match of class template partial specialization 'A' return 0; } Of course, in this case the specialization A<1, 1> should be used. BTW, this example compiles if I swap the order of A<n, n> and A<1, n>. bye, Christof
Apr 24 2005