When using Argument-Dependent Lookup in VC++2010, I casted the argument using decltype()
and encountered some weird results:
template<typename T>
struct Type {
typedef T type;
};
namespace NSC {
typedef enum {
mon
} DOW;
void proc1(DOW s, int a) {
printf("int proc1\n");
}
void proc1(DOW s, long long a) {
printf("long long proc1\n");
}
}
void p1(int a) {
printf("int p1\n");
}
void p1(long long a) {
printf("long long p1\n");
}
long long g;
int h;
int _tmain(int argc, _TCHAR* argv[])
{
NSC::DOW s=(NSC::DOW)0;
//proc1(s,(decltype(g))4.0);
proc1(s,(Type<decltype(2LL)>::type)4.0);
proc1(s,(Type<decltype(2)>::type)4.0);
p1((decltype(2LL))4);
p1((decltype(2))4);
return 0;
}
The above executed normally with these results:
long long proc1
int proc1
long long p1
int p1
Note that proc1()
was used to show that typecasting works with argument-dependent lookup while p1()
was to show that typecasting with decltype()
directly works with normal overloaded functions. But when I uncommented the line:
proc1(s,(decltype(g))4.0);
(note the cast was also done directly using a decltype()
instead of through the Type
template and involved argument-dependent lookup.) The lookup failed:
1>------ Build started: Project: cpptest, Configuration: Debug Win32 ------
1> cpptest.cpp
1>c:\work\cpptest\cpptest\cpptest.cpp(33): error C3861: 'proc1': identifier not found
Is the failure due to some intricate details of the lookup rule or just a compiler bug?