I'm using the following compiler:
Microsoft Visual C++ 2010
The following code crashes the compiler when it's compiled:
template<class T_>
void crasher(T_ a, decltype(*a)* dummy = 0){}
int main()
{
crasher(0);
return 0;
}
decltype(*a)*
used to enforce T_
to be a pointer-like type - such as char*
, int*
, and shared_ptr<int>
.
Why is it crashing? Is this a known bug?
Assuming your goal is
decltype(*a)*
used to enforceT_
to be a pointer-like type - such aschar*
, int*, and shared_ptr.
... what you need is simple template, not a code which happens to crash the compiler :)
Here is something that may work for you
#include <memory>
#include <iostream>
// uncomment this "catch all" function to make select(0) compile
// int select(...){ return 0;}
template<class T> int select(T*){ return 1;}
template<class T> int select(std::auto_ptr<T>){ return 1;}
// add boost::shared_ptr etc, as necessary
int main()
{
std::cout << select(0) << std::endl;
std::cout << select(std::auto_ptr<int>()) << std::endl;
std::cout << select(&std::cout) << std::endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With