I have the following code at the bottom of the post. The problem is: The resolved types are function pointers in a couple of cases although I expect to have instances of MyBar in all cases.
The code is compiled with gcc 4.8.4 and nvcc (7.0 and 7.5) and shows the same behaviour.
Is there anything in the standard that explains, what is happening here? MyBar myBar1()
seems to create a function pointer instead of a default constructed instance as I'd expect. But even given that, why is case 4 creating a function pointer? I wanted to create an instance, pass it to Bars ctor where it is bound to a const-ref. It should as well be able to be bound to a r-value-ref instead as its an r-value. Or am I missing anything?
#include <cstdio>
template<typename T_Type>
struct GetStaticAssertInfoType
{
typedef T_Type type;
};
#define PRINT_TYPE(TYPE) { typedef typename GetStaticAssertInfoType<TYPE>::SHOW_TYPE___ bla; }
template<class T_Foo>
void fooHost(T_Foo foo){
PRINT_TYPE(T_Foo);
foo.doIt();
}
template<class T1, class T2>
struct Bar{
T1 t1;
T2 t2;
Bar(const T1& t1 = T1(), const T2& t2 = T2()): t1(t1), t2(t2){}
void doIt(){ printf("1"); }
};
int main(int argc, char** argv){
typedef Bar<int, float> MyBar;
PRINT_TYPE(MyBar);
MyBar myBar1();
fooHost(myBar1); // Bar<int, float> (*)()
MyBar myBar2(int());
fooHost(myBar2); // Bar<int, float> (*)(int (*)()
MyBar myBar3(argc);
fooHost(myBar3);
MyBar myBar4(int(argc));
fooHost(myBar4); // Bar<int, float> (*)(int)
MyBar myBar5(1);
fooHost(myBar5); // Same as 3, no output (Bar<int, float>)
return 1;
}