Connecting Tech Pros Worldwide Forums | Help | Site Map

Compiler bug w/ partial function template specialization w/ multiple parameters

Michael Stembera
Guest
 
Posts: n/a
#1: Nov 16 '05
Here is a very simple piece of code to repro this bug.

template<typename T, int N> inline bool foo( void )
{
return true;
}

template<typename T> inline bool foo<T, 1>( void )
{
return false;
}

the partial specialization of foo fails to compile w/:
error C2768: 'foo' : illegal use of explicit template
arguments


I believe the above should compile fine. At the very
least it is inconsistent because doing the same thing
using either
A) classes
or
B) a template function w/ just one parameter
or
C) specializing both parameters
compiles. i.e., all of the below compile fine


1)
template<typename T, int N> class C
{
public:
inline static bool foo( void )
{
return true;
}
};

template<typename T> class C<T, 1>
{
public:
inline static bool foo( void )
{
return false;
}
};

2)
template<> inline bool foo<float, 1>( void )
{
return false;
}

3)
template<int N> inline bool foo( void )
{
return true;
}

template<> inline bool foo<1>( void )
{
return false;
}

What is the best way to submit this bug to the compiler
group at MS? BTW, I'm running MS VC++ 7.1.3088

Thanks,
Michael Stembera



tom_usenet
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Compiler bug w/ partial function template specialization w/ multiple parameters


On Mon, 24 Nov 2003 10:29:34 -0800, "Michael Stembera"
<m_stembera@yahoo.com> wrote:
[color=blue]
>Here is a very simple piece of code to repro this bug.
>
>template<typename T, int N> inline bool foo( void )
>{
> return true;
>}
>
>template<typename T> inline bool foo<T, 1>( void )
>{
> return false;
>}
>
>the partial specialization of foo fails to compile w/:
>error C2768: 'foo' : illegal use of explicit template
>arguments[/color]

Right, there is no such thing as partial function specialization
(overloading provides similar facilities).
[color=blue]
>I believe the above should compile fine. At the very
>least it is inconsistent because doing the same thing
>using either
>A) classes[/color]

Yup, partial template specialization is a class thing.
[color=blue]
>or
>B) a template function w/ just one parameter[/color]

Complete specialization is fine.
[color=blue]
>or
>C) specializing both parameters
>compiles. i.e., all of the below compile fine[/color]

Again, that's complete specialization.

[color=blue]
>What is the best way to submit this bug to the compiler
>group at MS? BTW, I'm running MS VC++ 7.1.3088[/color]

You could submit a feature request at comp.std.c++. It's not a bug,
but simply a feature that the standard C++ language lacks.

Tom
Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Compiler bug w/ partial function template specialization w/ multiple parameters


tom_usenet wrote:[color=blue]
> On Mon, 24 Nov 2003 10:29:34 -0800, "Michael Stembera"
> <m_stembera@yahoo.com> wrote:[/color]
[color=blue][color=green]
>> What is the best way to submit this bug to the compiler
>> group at MS? BTW, I'm running MS VC++ 7.1.3088[/color]
>
> You could submit a feature request at comp.std.c++. It's not a bug,
> but simply a feature that the standard C++ language lacks.[/color]

Partial specialization of function templates is a feature likely to be
included in the next revision of the C++ standard, expected in 5 years (!)
or so. Until then, the OP will have to find another way, or pressure
vendors (such as MS) to implement a non-conforming extension to support PTS
for function templates.

-cd


Closed Thread