I do not know if this is a duplicate report as there are other similar tickets
about problems with addresses of overloads, but as far as I've seen none seems
to be reported against template-ids.
Consider this snippet.
---
struct function
{
void (*outline)(void *);
};
template<typename _T >
struct info
{
_T *t_0;
};
template<typename _T >
static void my_fun(info<_T> *_args)
{
}
template<typename _T >
void f(_T t)
{
function fun = {
(void(*)(void)) my_fun<_T> // This is test.cpp:22
};
}
int main(int argc, char *argv[])
{
int a = 3;
f(a);
float b = 1.0f;
f(b);
return 0;
}
---
g++ yields the following errors
test.cpp: In function void f(_T) [with _T = int]:
test.cpp:28: instantiated from here
test.cpp:22: error: insufficient contextual information to determine type
test.cpp: In function void f(_T) [with _T = float]:
test.cpp:30: instantiated from here
test.cpp:22: error: insufficient contextual information to determine type
A workaround that seems to work is using a double casting, a first one that
"selects" the right overload (even if this would not be needed as we passed all
the template-arguments of the template-id of the function and no
template-parameter is left to deduce) before the original casting.
template<typename _T >
void f(_T t)
{
function fun = {
(void(*)(void))(void (*)(info<_T> *_args)) my_fun<_T>
};
}
Neither __typeof__(my_fun<_T>) or decltype (C++0x) seem able to figure the
precise 'my_fun<_T>'.
Usign __typeof__ like in
(void(*)(void))(__typeof__(my_fun<_T>)) my_fun<_T>
yields a
test.cpp:22: error: type of my_fun<int> is unknown
while decltype (g++ -std=c++0x) used like in
(void(*)(void)) (decltype(my_fun<_T>)) my_fun<_T>
ends with an ICE
test.cpp:22: internal compiler error: in finish_decltype_type, at
cp/semantics.c:4694
I'm not entirely sure whether this scenario should be regarded as valid but
icc, comeau and xlc++ accept this code, so I'm inclined to think g++ should
accept it too.
--
Summary: Address of templete function even if named as a
template-id is not properly determined
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: roger dot ferrer at bsc dot es
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45428