$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Imre (imre42_at_[hidden])
Date: 2006-08-02 12:08:50
Hi
I have some non-compiling code, and I'd like to know if it's a compiler 
bug, or something I'm doing wrong.
In the following code (it's a simplified version of the real code where 
I met the problem) the call to F<int> instantiates S<int>. I think the 
compiler should choose the specialized version of S<>, but it seems to 
use the primary template instead, leading to an invalid non-lvalue int 
-> int& conversion.
Strangely, if I explicitly instantiate S<int> (uncomment the commented 
line), then it compiles fine.
I also tried implementing enable_if and is_fundamental myself, and came 
to the exact same results.
Also tested that version (with the custom enable_if and is_fundamental) 
with the online Comeau compiler, and it compiled fine.
So, I'd like to know whether this stuff should work according to the 
standard, and if not, why; and if anyone could suggest a workaround that 
works with VC++ 7.1.
Thanks,
     Imre
Here's the code:
#include <boost/type_traits.hpp>
#include <boost/type_traits/is_fundamental.hpp>
#include <boost/utility/enable_if.hpp>
template <typename T, typename Enable = void>
struct S
{
         typedef T& type;
};
template <typename T>
struct S<T, typename
boost::enable_if_c<boost::is_fundamental<T>::value>::type>
{
         typedef T type;
};
//template struct S<int>;    // Compiles fine with VC if this line is 
uncommented
template <typename T>
typename S<T>::type F()
{
         return 0;
}
int main(int argc, char* argv[])
{
         F<int>();
         return 0;
}