The following code is not accepted by GCC 4.6:
void F(int x,char y)
{
}
template<typename T>
void G(T t)
{
F(t);
}
void F(int x)
{
}
int main()
{
G(5);
return 0;
}
Should it be?
If not, does anyone have a good idea for a work-around? The real world scenario where this occurs is where G is part of a library for solving a particular kind of problem, needing a user-supplied helper function called F. However, for different kinds of problems, F takes different number of parameters. A few sample implementations of F are shipped with the library.
What is happening is that depending on the #include-order used by the client, only the "wrong kind" of F may be visible at template declaration time, and GCC then gives up, without waiting until the user-provided, correct, F is defined. This is even though template instantiation happens after the correct F is defined.
Update: Yes I know it works if all declarations of F happen before G, or if all declarations of F happen after G. However, that doesn't really help me very much.
Update: In the code this minimal example is adapted from, F is really called 'read'. And the first declaration of read has nothing at all to do with the second. The first declaration is in one header file, and the second in another. I don't want to introduce 'strange' rules regarding include-file order, especially when the versions of 'read' have nothing to do with one another.