Topic: Defect Report: When is a non-type template argument specialized?


Author: japple@freeshell.org (Gina Yarmel)
Date: Mon, 22 Dec 2003 15:45:35 +0000 (UTC)
Raw View
[ Note: Forwarded to C++ Committee. -sdc ]

14.5.4/8 does not specify which non-type parameter a non-type argument
must have the same name as in order to qualify as non-specialized;
concievably, any parameter will do.

This leaves the struct B example in 14.5.4/9 with no specialized
arguments; both are names of a specialization parameter.

14.5.4/8 should read:
"A non-type argument is non-specialized if it is the name of its
corresponding parameter in the specialized parameter list.  If there
is no corresponding parameter, the argument is specialized. All other
non-type arguments are specialized."

Jim Apple


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "John H. Spicer" <jhs@edg.com>
Date: Mon, 22 Dec 2003 17:23:21 +0000 (UTC)
Raw View
Gina Yarmel wrote:
> [ Note: Forwarded to C++ Committee. -sdc ]
>
> 14.5.4/8 does not specify which non-type parameter a non-type argument
> must have the same name as in order to qualify as non-specialized;
> concievably, any parameter will do.
>
> This leaves the struct B example in 14.5.4/9 with no specialized
> arguments; both are names of a specialization parameter.
>
> 14.5.4/8 should read:
> "A non-type argument is non-specialized if it is the name of its
> corresponding parameter in the specialized parameter list.  If there
> is no corresponding parameter, the argument is specialized. All other
> non-type arguments are specialized."
>

I believe the wording in the standard is correct as-is.  There is no
correspondence between parameters of the partial specialization and the template
argument list of the primary template.  The partial specialization can have more
or fewer parameters.  For example,


template <class T1, class T2, int I> struct A {};
template <class T, int I> struct A<T,T,I> {};

int main()
{
         A<int,int,5> a;
}

With regard to the example in 14.5.4/9, a partial specialization can have no
specialized arguments.  My example above is such a partial specialization.

John Spicer
Edison Design Group

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: invalid@yahoo.co.nz (Graeme Prentice)
Date: Tue, 23 Dec 2003 04:24:02 +0000 (UTC)
Raw View
On Mon, 22 Dec 2003 17:23:21 +0000 (UTC), John H. Spicer wrote:

>
>Gina Yarmel wrote:
>> [ Note: Forwarded to C++ Committee. -sdc ]
>>
>> 14.5.4/8 does not specify which non-type parameter a non-type argument
>> must have the same name as in order to qualify as non-specialized;
>> concievably, any parameter will do.
>>
>> This leaves the struct B example in 14.5.4/9 with no specialized
>> arguments; both are names of a specialization parameter.
>>
>> 14.5.4/8 should read:
>> "A non-type argument is non-specialized if it is the name of its
>> corresponding parameter in the specialized parameter list.  If there
>> is no corresponding parameter, the argument is specialized. All other
>> non-type arguments are specialized."
>>
>
>I believe the wording in the standard is correct as-is.  There is no
>correspondence between parameters of the partial specialization and the template
>argument list of the primary template.

Hi John

Did you read the thread dated 20/12 - "When are non type parameters
specialised".  There appears to be a bug in the EDG compiler - see that
thread (or below) for the code.

14.5.4/9 gives this as an example of a "partially specialised non-type
argument expression"

template <int I, int J> struct B {};
template <int I> struct B<I, I> {}; // OK

There is no partially specialised non-type argument expression here.

Also in 14.5.4/9, the second bullet says "The type of a template
parameter corresponding to a specialized nontype argument shall not be
dependent on a parameter of the specialization." but does not make it
clear whether this refers to the template parameter in the primary
template, or in the specialisation or both.  Conceivably, an argument in
the specialisation could be said to "correspond to" a template parameter
in the specialisation if it is the same name.

Also, in the second example in the second bullet of 14.5.4/9 (the
array_ptr), the dependence of the type of the array_ptr parameter on a
parameter of the specialization is unclear.


> The partial specialization can have more
>or fewer parameters.  For example,
>
>
>template <class T1, class T2, int I> struct A {};
>template <class T, int I> struct A<T,T,I> {};
>
>int main()
>{
>         A<int,int,5> a;
>}
>
>With regard to the example in 14.5.4/9, a partial specialization can have no
>specialized arguments.  My example above is such a partial specialization.

Yes, but does it have any partially specialized non-type arguments?

Does the standard say what was intended  - the error message given by
the Comeau and Borland compilers for the code in the 20/12 thread
doesn't match the wording in the standard.  i.e. For this code ...

template<typename T, T N, int X>
struct base {};

template<typename T, T N>
struct base<T,N,0> {};

int main() {}

The Comeau 4.3.3 compiler says

"error - the type of partial specialization template parameter constant
"N" depends on another template parameter"

but this is not precisely what the standard says.

The Borland bcc32 compiler says
"Partial specializations may not specialize dependent non-type
parameters ('N')"

but "N" is not specialised.

Graeme

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rani_sharoni@hotmail.com (Rani Sharoni)
Date: Tue, 23 Dec 2003 17:05:45 +0000 (UTC)
Raw View
invalid@yahoo.co.nz (Graeme Prentice) wrote in message
> Does the standard say what was intended  - the error message given by
> the Comeau and Borland compilers for the code in the 20/12 thread
> doesn't match the wording in the standard.  i.e. For this code ...
>
> template<typename T, T N, int X>
> struct base {};
>
> template<typename T, T N>
> struct base<T,N,0> {};
>
> int main() {}

I didn't mean to participate in this thread but I will since the code
you presented led me to discover internal compiler error (ICE) in both
VC and EDG.

My primary tool for checking whether class template specialization is
valid is 15.5.4.2 which is partial ordering. This is the actually
motivation behind the canonical partial specializations simulation
technique (for the favor of old compilers). I'm quite happy that I
didn't used this technique for a while ;-)

Your code is rewritten to the following:

template<typename T, T N, int X>
struct base {};

template<typename T, T N, int X>
char* f(base<T,N,X>) { return 0; }

template<typename T, T N>
long* f(base<T,N,0>) { return 0; }

long* p = f(base<int,1, 0>());

EDG, VC, GCC and I believe that the code is well-formed and which
means that the above function templates are ordered and therefore your
code is also well-formed.

I tweaked the code a bit and got the ICE I promised:
template<typename T, T N>
struct base {};

template<typename T, T N>
int f(base<T,N>) { return 0; }

template<typename T>
int f(base<T,1>) { return 0; }

int p = f(base<int,1>());

GCC correctly rejected the code due an ambiguity.

Rani

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]