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

  • Thread starter Thread starter Michael Stembera
  • Start date Start date
M

Michael Stembera

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
 
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

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

Yup, partial template specialization is a class thing.
or
B) a template function w/ just one parameter

Complete specialization is fine.
or
C) specializing both parameters
compiles. i.e., all of the below compile fine

Again, that's complete specialization.

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

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
 
tom_usenet said:
On Mon, 24 Nov 2003 10:29:34 -0800, "Michael Stembera"


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.

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
 
Back
Top